使用Python获取Facebook见解

时间:2019-01-28 15:19:48

标签: python facebook facebook-insights

我正在尝试使用python从我的Facebook页面获取印象,我只是在要求印象以使其发挥作用,但是从帖子中获取所有数据将是很棒的。我的代码如下:

import facebook
import requests
import json

# Give the date Unixtime format
a = u'12/30/2018'
b = u'12/31/2018'
since = datetime.datetime.strptime(a, "%m/%d/%Y")
until = datetime.datetime.strptime(b, "%m/%d/%Y")

# Parse and make the URL
token = 'MyAccessToken'
graph = facebook.GraphAPI(access_token=token, version=3.1)
page_info = graph.get_object('me')
page_id = page_info['id']
base = 'https://graph.facebook.com/v3.2'
node = '/' + page_id + '/insights/page_impressions'
url = base + node
parameters = {'period': 'week', 'access_token': token,'since': since, 
              'until': until}
object1 = requests.get(url, params=parameters).text.encode('utf-8')
data = json.loads(object1)

print(data)

我没有收到任何错误,只是数据数组为空:

{'data': [], 'paging': {'previous': 
 'https://graph.facebook.com/v3.2/pageID/insights?period=week&access_token=MyAccessToken&metric=page_impressions_unique&since=1547994299&until=1548253499', 'next': 
 'https://graph.facebook.com/v3.2/pageID/insights?period=week&access_token=MyAccessToken&metric=page_impressions_unique&since=1548512699&until=1548771899'}}

我已经检查了this个帖子,并且对此令牌具有“ read_insights”权限以及该页面的管理/所有者权限,我也阅读了this帖子,但答案不完整,并且发生同样的事情。

  

有人知道如何使用Python正确检索Facebook Insights的数据吗?

0 个答案:

没有答案