问题
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'data': []}
回答1:
Try this code:
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
metric is not parameter :)
来源:https://stackoverflow.com/questions/44105005/accessing-facebook-api-page-insights-with-python