简体   繁体   English

Facebook Graph API + Facebook页面

[英]Facebook Graph API + Facebook Pages

使用Facebook的Graph API,给定用户名xyz(假设他们已经对我的网站进行了身份验证),如何获取用户管理的所有Facebook页面的列表?

The accounts property on the user object says: user对象上的accounts属性表示:

The Facebook pages owned by the current user. 当前用户拥有的Facebook页面。 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. 如果已授予manage_pages权限,则此连接还会生成access_tokens,可用于代表页面查询Graph API。

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

After getting access token you can get all details of list of all of the facebook pages that the user administers. 获取访问令牌后,您可以获取用户管理的所有Facebook页面列表的所有详细信息。

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

Use an fql query! 使用fql查询! 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. 您还可以限制名称。 ie pages with empty names A sample fql query which gives you the page details as well. 即具有空名称的页面示例fql查询,它还为您提供页面详细信息。

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 UserId - 管理员的ID

NOTE This method will not work from version 2.1 of graph api as fql was deprecated from that version onwards 注意此方法不适用于图api的2.1版本,因为从该版本开始不推荐使用fql

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! 这当然是在为fb用户创建会话之后! The $uid would be the profile id# of the specific facebook user your returning of a list of managed pages for. $uid将是您返回托管页面列表的特定Facebook用户的个人资料ID#。

@rmorrison - This is not graph API though. @rmorrison - 这不是图API。 With the new "like" addition, you can use this URL: h ttps://graph.facebook.com/me/likes?access_token=blah! 使用新的“喜欢”添加,您可以使用此URL:h ttps://graph.facebook.com/me/likes?access_token = blah! or h ttps://graph.facebook.com/USER_ID/likes?access_token=blah! 或者https://graph.facebook.com/USER_ID/likes?access_token = blah!

You can get list of pages from a simple Facebook Graph API Hit. 您可以从简单的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. 它将为用户创建的页面列表。

Fql is the best way to get the pages of the user for which he is the admin. Fql是获取他是管理员的用户页面的最佳方式。 As the others like likes of user will give all the pages that the user like. 像其他人一样喜欢用户会给出用户喜欢的所有页面。

access_token is valid for an hour or less. access_token有效期为一小时或更短。 What should someone do in order to get the details even after. 为了获得细节,有人应该怎么做。 I was trying to result get the result from 我试图得到结果

https://graph.facebook.com/v2.3/search?q=coffee&type=place&center=37.76,-122.427&distance=1000&access_token=xyz https://graph.facebook.com/v2.3/search?q=coffee&type=place&center=37.76,-122.427&distance=1000&access_token=xyz

This worked for an hour or so but how do i get the result after an hour...without going for a login. 这工作了一个小时左右但是如何在一小时后得到结果......无需登录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM