我正在尝试通过 python 脚本从 Instagram 图形 API 获取长期访问令牌。无论我做什么,我都会收到以下错误:
{"error":{"message":"Missing client_id parameter.","type":"OAuthException","code":101,"fbtrace_id":"AogeGpzZGW9AwqCYKHlmKM"}}
我的脚本如下:
import requests
refresh_token_url = 'https://graph.facebook.com/v19.0/oauth/access_token'
payload = {
'grant_type': 'fb_exchange_token',
'client_id': '1234567890123456'
'client_secret': '1234abcd1234abcd1234abcd',
'fb_exchange_token':'abcd1234'
}
r = requests.get(refresh_token_url, data=payload)
我确信传递了 client_id 参数。我还通过打印验证了
r.request.body
相反,如果我使用Postman应用程序发送请求,则请求成功:
为什么我不断收到该错误消息? 谢谢!
通过GET参数调用的Postman。
在修改版本中,使用 params 参数代替数据。此更改会将有效负载中的参数作为查询字符串附加到 URL,
所以你的代码需要改变它
import requests
refresh_token_url = 'https://graph.facebook.com/v19.0/oauth/access_token'
payload = {
'grant_type': 'fb_exchange_token',
'client_id': '1234567890123456',
'client_secret': '1234abcd1234abcd1234abcd',
'fb_exchange_token': 'abcd1234'
}
r = requests.get(refresh_token_url, params=payload)