亚马逊广告API通过脚本获取授权代码

问题描述

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

任何想法我该如何实施?

谢谢。

解决方法

您需要什么:

  • developers.amazon.com上的注册申请
  • 此应用程序的{li> client_idclient_secret
  • 同意访问Amazon Advertising Account(通过“使用Amazon登录”完成)

通过同意流程,您将获得refresh token
使用client_idclient_secretrefresh token,您可以构建一个Python脚本来接收access token-使用access token,您可以访问Amazon Advertising 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请求...

,

我遇到了同样的问题,并使用 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)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...