facebook - 检索 Instagram 标记帖子的所有响应页面时出错
问题描述
我正在尝试获取标记了业务页面的所有 Instagram 帖子的数据。响应是一组 25 个分页对象。每个对象都有几个页面(下一页的端点在'next'键中)。能够检索前 2 个对象的数据(所有页面)。之后我得到: {'error': {'message': '发生了意外错误。请稍后重试您的请求。', 'type': 'OAuthException', 'is_transient': True, 'code': 2, 'fbtrace_id': 'AVCL6iRv2sQ80t87zS0Nysa'}}
我认为我没有超出任何速率限制
import requests
from pprint import pprint
import pandas as pd
#update this with the latest access token
temp_access_token = "[REDACTED]"
#replaced client_secret and client_id with xxxx
long_lived_access_token = requests.get("https://graph.facebook.com/v11.0/oauth/access_token?grant_type=fb_exchange_token&client_id=xxxxxxxxxxxxxxx&client_secret=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&fb_exchange_token="+temp_access_token)
long_lived_access_token = long_lived_access_token.json()['access_token']
#replaced business account id with xxxx
response = requests.get("https://graph.facebook.com/v11.0/xxxxxxxxxxxxxxxxx?fields=instagram_business_accounts%7Btags%7Bid%2Ccaption%2Ccomments_count%2Clike_count%2Ctimestamp%2Cusername%2Cmedia_product_type%2Cowner%2Cmedia_type%2Cpermalink%7D%7D&access_token="+long_lived_access_token)
response_obj = response.json()
response_obj = response_obj['instagram_business_accounts']['data']
data_list = []
for idx, obj in enumerate(response_obj):
data_list+=obj['tags']['data']
if obj['tags']['paging']['next']:
temp_obj = requests.get(obj['tags']['paging']['next']).json()
while True:
if 'paging' not in temp_obj:
data_list+=temp_obj['data']
break
data_list+=temp_obj['data']
#next_set.add((temp_obj['paging']['next']))
temp_obj = requests.get(temp_obj['paging']['next']).json()
print(idx)
解决方案
推荐阅读
- c++ - 使用等于运算符时遇到问题。以退出代码 11 结束
- mysql - 在 WHERE 子句中使用“IN”运算符会以某种方式反转子查询的顺序
- python - 用opencv和python计算区域相关图
- python - “Series[Dtype]”类型的参数不能分配给“DataFrame”类型的参数
- database - 错误 ORA-00054 资源繁忙并使用指定的 NOWAIT 获取或超时已过期
- c# - 无法使用隐式转换将字符串转换为类型
- android - 重新加载完全完成后如何仅摆脱刷新小部件
- opengl - 如何在 SDL2 中使用 OpenGL 上下文?
- r - 绘制由两个变量分组的数据框的堆积条形图
- python - 轴旋转