使用Python访问Facebook API页面见解 [英] Accessing Facebook API Page Insights with Python

查看:299
本文介绍了使用Python访问Facebook API页面见解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前是Facebook Page的管理员,我试图从中访问一些见解,并且在获得对API的任何访问权限时遇到很多麻烦.目前,它目前不返回任何数据.谁能找出原因?尝试编写代码,让我可以在参数的指标"部分下输入要搜索的指标.

I'm currently an administrator of a Facebook Page and I'm attempting to access some insights from it and I'm having lots of trouble gaining any access to the API. At the moment, it currently returns no data. Can anyone figure out why? Trying to get a code written that'll let me input whatever metrics I am searching for under the 'metric' part of the parameters.

graph=facebook.GraphAPI(access_token=token)
page_info=graph.get_object('me') # returns metadata for page
page_ID=page_info['id'] # returns the page ID to be used in calling the URL

base='https://graph.facebook.com/v2.9'
node='/'+ page_ID + '/insights'
url=base+node
parameters={'period':'week','access_token':token,'metric':'page_impressions'}
object=requests.get(url,params=parameters).text.encode('utf-8')
data=json.loads(object)
print data    

这将返回以下内容(我已经取出了访问令牌):

This returns the following (I've taken out the access token where it would be):

{u'paging':{

{u'paging': {

u'next':u'

u'next': u'https://graph.facebook.com/v2.9/1509164045966534/insights?access_token=(my_hidden_token)&metric=page_impressions&period=week&since=1495255384&until=1495514584',

u'previous':u'

u'previous': u'https://graph.facebook.com/v2.9/1509164045966534/insights?access_token=(my_hidden_token)&metric=page_impressions&period=week&since=1494736984&until=1494996184'

},

u'data':[]}

u'data': []}

推荐答案

尝试以下代码:

base='https://graph.facebook.com/v2.9'
node='/'+ page_ID + '/insights/page_impressions'
url=base+node
parameters={'period':'week','access_token':token}
object=requests.get(url,params=parameters).text.encode('utf-8')
data=json.loads(object)
print data

指标不是参数:)

这篇关于使用Python访问Facebook API页面见解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆