我无法弄清楚如何从页面获取fan_count。 我总是得到这个错误
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,我无法弄清楚如何提供更多权限才能获得&#39; fan_count&#39;数据
以下是我使用的代码:
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']
答案 0 :(得分:1)
从Graph API的v2.4开始,您必须指定要返回的字段。这将是正确的API调用:
.alert {
-webkit-animation:fadeout 6s linear;
animation:fadeout 6s linear;
opacity:0;
}
@-webkit-keyframes fadeout{
0%{opacity:1;}
83.33%{opacity:1;}
100%{opacity:0;}
}
@keyframes fadeout{
0%{opacity:1;}
83.33%{opacity:1;}
100%{opacity:0;}
}
它被称为&#34;声明字段&#34;。