我试图通过graphapi获取链接列表的公众参与度指标。因为有很多,批处理请求是必要的,以避免达到速率限制。使用Facebook提供的engagement endpoint for links和{a2},我将批处理请求格式化为字典列表,并通过POST而不是get提交。在
但是当我运行我的代码(见下文)时,我得到了一个不受支持的Post请求错误。在
我在后面呼气,任何帮助都将不胜感激。在
我的代码是:
import requests
import json
from fbauth import fbtoken
link1 ='https://www.nytimes.com/2018/07/02/world/europe/angela-merkel-migration-coalition.html'
link2 ='https://www.nytimes.com/2018/07/02/world/europe/trump-nato.html'
# input dictionary for request
batch=[{"method":"GET", "relative_url": '/v3.0/url/?id={0}'.format(link1)},
{"method":"GET", "relative_url": '/v3.0/url/?id={0}'.format(link2)}]
url = 'https://graph.facebook.com'
payload = json.dumps(batch)
headers = {'access_token : {0}'.format(fbtoken)}
response = requests.post(url, data=payload)
Robj = response.json()
print(Robj)
错误就在这里:
^{pr2}$
您需要使用
batch
参数传递批处理请求,如下所示:payload = {'batch': json.dumps(batch)}
相关问题 更多 >
编程相关推荐