首页 文章

为什么我无法从Facebook Graph API中看到对象的所有统计信息

提问于
浏览
0

我正在使用Python SDK for Facebook's Graph API来获取Facebook页面被喜欢的次数 . 我去了API Explorer获取访问令牌 . 我第一次从应用程序的下拉菜单中选择"Graph API Explorer"(右上角) . 然后我运行了这段代码,并取回了我的预期:

import facebook

ACCESS_TOKEN = "**********"

facebook_page_id = "168926019255" # https://www.facebook.com/seriouseats/
graph = facebook.GraphAPI(ACCESS_TOKEN)
page = graph.get_object(facebook_page_id)

print page

{u'about': u'The Destination for Delicious',
 u'can_post': True,
 u'category': u'Website',
 u'checkins': 0,
 u'cover': {u'cover_id': u'10154881161274256',
  u'id': u'10154881161274256',
  u'offset_x': 0,
  u'offset_y': 43,
  u'source': u'https://scontent.xx.fbcdn.net/t31.0-0/p180x540/13391436_10154881161274256_2605145572103420621_o.jpg'},
 u'founded': u'December 2006',
 u'has_added_app': False,
 u'id': u'168926019255',
 u'is_community_page': False,
 u'is_published': True,
 u'likes': 159050,
 u'link': u'https://www.facebook.com/seriouseats/',
 u'mission': u'Serious Eats is a site focused on celebrating and sharing food enthusiasm through recipes, dining guides, and more! Our team of expert editors and contributors are the last word on all that\u2019s delicious.',
 u'name': u'Serious Eats',
 u'parking': {u'lot': 0, u'street': 0, u'valet': 0},
 u'talking_about_count': 3309,
 u'username': u'seriouseats',
 u'website': u'http://www.seriouseats.com',
 u'were_here_count': 0}

然后我回到API Explorer并将应用程序更改为我最近创建的新Facebook应用程序 . 我生成了一个新的Access Token,将其交换出来并运行上面的代码 . 这是我在 page 变量中得到的响应:

{u'id': u'168926019255', u'name': u'Serious Eats'}

如您所见,它只返回页面的 idname ,但缺少其他属性 - 特别是 likes 属性 .

所以, do I need to give my application permissions to see all attributes for an object? 我已经尝试从我的App Id和App Secret生成访问令牌,但仍然得到相同的结果 .

1 回答

  • 2

    这里有两件事要看 .

    • facebook API的版本 . 在你得到大量结果的第一个例子中,你使用的是 version 2.2 (这是facebook python sdk的默认版本) . 当你去Facebook创建新的应用程序时,它很可能使用 version 2.6 作为默认值 . 因此,它现在只返回两到三个字段,其余的你需要请求 .

    • 假设您确实使用的是2.6版本,那么您的要求是什么

    使用以下代码

    page = graph.get_object(id='168926019255', fields='about, affiliation, awards, category')
    

    这会给你

    {'id': '168926019255', 'about': 'The Destination for Delicious', 'category': 'Website'}
    

    现在你想得到喜欢的 . 由于喜欢不是默认字段而是“边缘”,因此您需要使用“连接”询问它们 . 为此,您可以执行以下操作:

    page = graph.get_connections(id='168926019255', connection_name='likes')
    

    这将给你所有的喜欢

    {'data': [{'id': '134049266672525', 'name': 'Tom Colicchio'}, {'id': '143533645671591', 'name': 'Hearth'}, {'id': '57909700259', 'name': 'Toro'}, ....
    

相关问题