我正在尝试使用 python 脚本从亚马逊广告中获取报告,但我找不到获取授权码的方法。所有亚马逊文档都参考网站,没有自动脚本。
知道如何实施吗?
谢谢。
我正在尝试使用 python 脚本从亚马逊广告中获取报告,但我找不到获取授权码的方法。所有亚马逊文档都参考网站,没有自动脚本。
知道如何实施吗?
谢谢。
我遇到了同样的问题,使用 tector 的评论我构建了一个简单的函数,它使用刷新令牌(永不过期)来生成授权码,有效期为 60 分钟:
import requests
import json
host = 'https://api.amazon.com/auth/o2/token'
body = {
"grant_type": "refresh_token",
'client_id': YOUR CLIENT ID,
'refresh_token': YOUR REFRESH TOKEN,
'client_secret': YOUR CLIENT SECRET
}
headers = {"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"}
def authenticator():
r = requests.post(host, body,
headers=headers)
r.raise_for_status()
r = r.json()
with open('FILENAME.json', 'w') as f:
json.dump(r, f)
你需要什么:
developers.amazon.com
client_id
对于client_secret
这个应用程序作为同意过程的结果,您将获得一个refresh token
.
使用client_id
、client_secret
和 ,refresh token
您可以构建一个 python 脚本来接收access token
- 并且access token
您可以访问亚马逊广告 API。
资源:
https ://advertising.amazon.com/API/docs/en-us/setting-up/account-setup
https://advertising.amazon.com/API/docs/en-us/get-started/overview
编辑:我建议使用Postman或 SoapUI 之类的工具来轻松测试 auth 和 api 请求...