Facebook: get list of pages that a user is admin of

99,725

Solution 1

Its simple with Graph API. Steps:

  1. Get the manage_pages permission from the user (extended permissions).
  2. 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.

Solution 2

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;
       }}

Solution 3

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

Solution 4

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'.

Solution 5

You ask for the permission with the JavaScript SDK on login

FB.login(function(){}, {perms:'manage_pages'});

and then once they log in you can retrieve the pages (and apps) as follow :

FB.api('/me/accounts', function(response){
    console.log(response);
})
Share:
99,725

Related videos on Youtube

EoghanM
Author by

EoghanM

Updated on November 03, 2020

Comments

  • EoghanM
    EoghanM over 3 years

    I'm using the graph api.

    I have a logged in user, and want to get back a list of page ids of all the pages that the user is an admin of.

    Is there a way of doing this? The docs are pretty bad - and circular.

    • Darkwonder
      Darkwonder over 3 years
      10 years later, and the documentation is still bad.
    • Andy Wallace
      Andy Wallace over 2 years
      bad is a SEVERE understatement. Gack.
  • EoghanM
    EoghanM about 12 years
    Switching answers as this sounds like the more standard/stable way of doing it. Although I would warn against any use of the word 'simple': everything is simple once you know how :)
  • Avisek Chakraborty
    Avisek Chakraborty about 12 years
    ya. u r right. But there can be several solutions to a problem. We need to choose the simplest among them.
  • Jepser Bernardino
    Jepser Bernardino about 12 years
    If you're using FB PHP SDK it's easier: just $user_admin_pages = $facebok->api('/me/accounts');
  • ObscureRobot
    ObscureRobot over 11 years
    As of December 2012, the documentation for 'accounts' states that it will return pages and apps the user owns.
  • Yuval A.
    Yuval A. about 11 years
    The advantage of querying with FQL vs. using a graph request is that graph always forces the returned data to be 'paged' (it only returns the first few results, and a link to the next few) - while in FQL it always returns the entire result-set in one time.
  • Kees C. Bakker
    Kees C. Bakker over 10 years
    What is the difference between {perms: 'manage_pages'} and {scope: 'manage_pages'}?
  • Soorajlal K G
    Soorajlal K G over 9 years
    Thanks. It lists pages only if the current user administrates app. Is there any way to list pages of another person?
  • Soorajlal K G
    Soorajlal K G over 9 years
    Is thr any way to list pages of another person
  • Serge S.
    Serge S. almost 9 years
    Where have you found that me/accounts supports type query parameter?
  • Raptor
    Raptor almost 9 years
    You seem to use some frameworks in your codes, would you mind to explain it?
  • Raptor
    Raptor almost 9 years
    @SoorajlalKG no, you won't have the permission to do so.
  • Kapitein Witbaard
    Kapitein Witbaard over 8 years
    As of August 2014: "The FQL and REST APIs are no longer available in v2.1: Previously announced with v2.0, apps must migrate to versioned Graph API calls starting with v2.1.". In other words, the FQL can no longer be used.
  • Maha Dev
    Maha Dev over 8 years
    Can i get any facebook page details without login? i have my app id and app secret
  • activ8
    activ8 over 7 years
    ^ I need the same. Did you find anything about ?
  • Igorzovisk
    Igorzovisk over 5 years
    Just posting a code is not a good answer, from my point of view.
  • Kris Stern
    Kris Stern about 4 years
    Think you can list the pages of another Facebook user if you supply their id in lieu of me in the endpoint for the GET request...
  • Masroor
    Masroor over 3 years
    I agree with @Soorajkal, this does not return the pages if the page is not in the app administered by the user. Which is what I need. Is there a way to do it?