Facebook: get list of pages that a user is admin of
Its simple with Graph API. Steps:
- Get the
manage_pages
permission from the user (extended permissions). - Call the Graph API - https://graph.facebook.com/me/accounts
You can test this procedure in the graph explorer -> Just click on 'Get Access Token' button-> under 'Extended permission' check 'manage_pages' & submit it. It will give you the admin-page-details JSON.
I solved it with some FQL:
FB.api({method: 'fql.multiquery',
access_token: <access_token>,
queries: {
query1: 'select page_id from page_admin where uid = ' + <uid>,
query2: 'select page_id, name, page_url from page where page_id in (select page_id from #query1)'
}
}, function(queries){
var pages = queries[1].fql_result_set;
}}
go to this address
https://developers.facebook.com/tools/explorer/431294226918345/?method=GET&path=me%2Faccounts%3Ftype%3Dpage`
Just click on get Access token and go to extended Permission
Check the manage_pages checkbox
and click Get Access Token
Then under FQL write this
me/accounts?type=page
Click on Submit . and you will get all page lists that logged in user admin
You can call FB.api(/me/accounts)
if you don't want to use FQL.
'accounts' is a connection of the User object. See the documentation for this @ http://developers.facebook.com/docs/reference/api/user
Of course, with Facebook, there's always a catch. Right now this method will return not only the pages the user is an admin of, but also what applications they have installed. I'm almost positive this is NOT the intended behavior - I seem to remember using this a few months ago and only getting a list of pages. The documentation makes no mention of applications in this list either.
This is an easy problem to solve though - Facebook returns the name, category, and id for each item on the list, and each application has a category of 'Application'. I'm simply making sure I only list items whose category is not 'Application'.