首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >fan_count问题

fan_count问题
EN

Stack Overflow用户
提问于 2016-05-30 16:16:22
回答 1查看 144关注 0票数 0

我不知道如何从页面中获取fan_count。我总是会犯这个错误

代码语言:javascript
复制
Traceback (most recent call last):
  File "./facebook_api.py", line 37, in <module>
facebook_graph.get_object('somepublicpage')['fan_count']
KeyError: 'fan_count'

该对象只包含id/name,我不知道如何授予更多权限以获取“fan_count”数据。

下面是我使用的代码:

代码语言:javascript
复制
import facebook
import urllib
import urlparse
import subprocess
import warnings


warnings.filterwarnings('ignore', category=DeprecationWarning)


oauth_args = dict(client_id = FACEBOOK_APP_ID,
              client_secret = FACEBOOK_APP_SECRET,
              grant_type = 'client_credentials')
oauth_curl_cmd = ['curl',
              'https://graph.facebook.com/oauth/access_token?' +      urllib.urlencode(oauth_args)]
oauth_response = subprocess.Popen(oauth_curl_cmd,
                              stdout = subprocess.PIPE,
                              stderr = subprocess.PIPE).communicate()[0]

try:
    oauth_access_token = urlparse.parse_qs(str(oauth_response))['access_token'][0]
except KeyError:
    print('Unable to grab an access token!')
exit()

print oauth_access_token
facebook_graph = facebook.GraphAPI(oauth_access_token)
print facebook_graph.get_object(PROFILE_ID)['fan_count']
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-30 16:44:58

由于Graph的2.4版本,您必须指定要返回的字段。这将是正确的API调用:

/{page-id}?fields=name,fan_count

它被称为“声明字段”。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37530001

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档