Facebook Graph API + Facebook Pages

后端 未结 9 1489
温柔的废话
温柔的废话 2021-02-06 09:17

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?

相关标签:
9条回答
  • 2021-02-06 09:50

    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

    0 讨论(0)
  • 2021-02-06 09:51

    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

    0 讨论(0)
  • 2021-02-06 09:54

    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"
          }
       }
    }
    
    0 讨论(0)
  • 2021-02-06 10:00

    Here's what I use. It works perfect

    $pages = $facebook->api(array('method' => 'fql.query','query' => 'SELECT page_id FROM page_admin WHERE uid = '.$uid.''));
    
    foreach($pages as $k=>$v) {
        echo 'page id#:'.$v['page_id'].'<br/>';
    }
    

    This is of course after you have the session created for the fb user! The $uid would be the profile id# of the specific facebook user your returning of a list of managed pages for.

    0 讨论(0)
  • 2021-02-06 10:02

    You can get list of pages from a simple Facebook Graph API Hit.

    https://graph.facebook.com/{user-id}/accounts?access_token={access-token}
    

    It will give a list of pages for user which he/she has created.

    0 讨论(0)
  • 2021-02-06 10:04

    @rmorrison - This is not graph API though. With the new "like" addition, you can use this URL: h ttps://graph.facebook.com/me/likes?access_token=blah! or h ttps://graph.facebook.com/USER_ID/likes?access_token=blah!

    0 讨论(0)
提交回复
热议问题