1

我正在尝试使用 python 脚本从亚马逊广告中获取报告,但我找不到获取授权码的方法。所有亚马逊文档都参考网站,没有自动脚本。

知道如何实施吗?

谢谢。

4

2 回答 2

0

我遇到了同样的问题,使用 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)
于 2021-05-21T11:54:56.933 回答
0

你需要什么:

  • 注册申请developers.amazon.com
  • client_id对于client_secret这个应用程序
  • 同意访问亚马逊广告账户(通过“登录亚马逊”完成)

作为同意过程的结果,您将获得一个refresh token.
使用client_idclient_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 请求...

于 2020-09-28T13:06:57.353 回答