Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Graph API + Facebook Pages

Using Facebook's Graph API, given a username xyz (assuming they've authenticated my site), how do I get a list of all of the facebook pages that the user administers?

like image 903
rmorrison Avatar asked Jun 09 '10 23:06

rmorrison


People also ask

How do I get Facebook Page Insights on graph API?

You can access Page Insights by typing /insights after the name of your page in the URL field. This command will retrieve all of the Insights associated with your Page. Type "/insights" after your company name. Click the Submit button.

Does Facebook use graph API?

The Graph API is the primary way to get data into and out of the Facebook platform. It's an HTTP-based API that apps can use to programmatically query data, post new stories, manage ads, upload photos, and perform a wide variety of other tasks.

How do I make a graph API on Facebook?

Go to Tools – Graph API Explorer to generate Access Tokens for various kinds of API that you would like to use in your app. Choose the app and kind of token you need in the drop down menus in the left part of the screen. Then click “Generate Access Token”.


4 Answers

The accounts property on the user object says:

The Facebook pages owned by the current user. If the manage_pages permission has been granted, this connection also yields access_tokens that can be used to query the Graph API on behalf of the page.

http://developers.facebook.com/docs/reference/api/user

like image 57
dar Avatar answered Oct 13 '22 18:10

dar


After getting access token you can get all details of list of all of the facebook pages that the user administers.

https://graph.facebook.com/[FACEBOOKUSERID]?metadata=1&access_token=

The output will look like

{
   "name": "Facebook Developer Garage Austin - SXSW Edition",
   "metadata": {
      "connections": {
         "feed": "http://graph.facebook.com/331218348435/feed",
         "picture": "https://graph.facebook.com/331218348435/picture",
         "invited": "https://graph.facebook.com/331218348435/invited",
         "attending": "https://graph.facebook.com/331218348435/attending",
         "maybe": "https://graph.facebook.com/331218348435/maybe",
         "noreply": "https://graph.facebook.com/331218348435/noreply",
         "declined": "https://graph.facebook.com/331218348435/declined"
      }
   }
}
like image 26
PrateekSaluja Avatar answered Oct 13 '22 18:10

PrateekSaluja


Use an fql query! That is the best way to get the pages for which the user is admin. You will also be able to restrict the names also. i.e pages with empty names A sample fql query which gives you the page details as well.

SELECT page_id,page_url,name,pic_square FROM page WHERE page_id IN (SELECT page_id FROM page_admin WHERE uid = " + **UserId** + ") and name!='' 

UserId -- Id of the admin

NOTE This method will not work from version 2.1 of graph api as fql was deprecated from that version onwards

like image 25
Tech Avatar answered Oct 13 '22 19:10

Tech


I found the answer, you need to use FQL, passing in the appropriate access_token:

https://api.facebook.com/method/fql.query?query=SELECT%20page_id%20FROM%20page_admin%20WHERE%20uid=XXXX&access_token=YYYY

like image 26
rmorrison Avatar answered Oct 13 '22 18:10

rmorrison