二、创建API authorization 和 refresh tokens(Amazon Advertising API 授权)

目的:获取访问Advertising API 的 access_token,refresh_token

先决条件:《一、创建安全配置文件(Amazon Advertising API 授权)》


步骤1:获取授权码

  • Amazon Advertising API授权代码用于生成 authorization 和 refresh tokens。授权代码在调用API的区域中生成。 用于检索授权码的API调用在每个区域都有不同的URL
区域URL 前缀
North America (NA)https://www.amazon.com/ap/oa
Europe (EU)https://eu.account.amazon.com/ap/oa
Far East (FE)https://apac.account.amazon.com/ap/oa
  • API调用查询参数:
参数名描述
client_idThe Client ID value that you retrieved in the prerequisites section of this document.
scopeThe OAuth 2.0 permission scope used to limit the application's access to an advertiser's account.
For the Sponsored Brands, Sponsored Display, and Sponsored Products APIs, set scope to cpc_advertising:campaign_management.
For the Data Provider API, set scope to advertising::audiences.
For the DSP API, set scope to advertising::campaign_management.
response_typeThe type of response. Always set to code.
redirect_uriThe value from the Allowed Return URLs field, retrieved in the prerequisites section of this document.
  • 例如,要在North America (NA) 区域生成授权码,请用您的值替换以下URL中的值:
https://www.amazon.com/ap/oa?client_id=YOUR_LWA_CLIENT_ID&scope=cpc_advertising:campaign_management&response_type=code&redirect_uri=YOUR_RETURN_URL
  • 接下来,将带有替换值的URL粘贴到浏览器的地址窗口中,然后导航到该URL。

步骤2:登录

  • 导航到URL后,系统将提示您登录。
  • 对于除数据提供者API以外的所有广告API,请在登录亚马逊时使用您用于注册应用程序的帐户登录。
  • 对于数据提供者API,请从数据提供者API的其他设置步骤中回忆起,您为每个区域创建了单独的DSP帐户。使用与步骤1中使用的URL相同的区域使用DSP帐户登录。

步骤3:授予应用程序访问权限

  • 登录后,您将被重定向到同意书:

  • 要授予应用程序访问Amazon Advertising的权限,请选择Allow。要拒绝应用程序访问Amazon Advertising,请选择Cancel

步骤4:获取授权码

  • 如果您在步骤3中选择了允许,则将浏览器重定向到与步骤1中使用的URL相同区域的Amazon网站。
  • 从浏览器的地址栏中选择并复制URL字符串。将URL字符串粘贴到文本编辑器中。记下代码查询参数的值。代码查询参数是在下一步中与授权令牌和刷新令牌交换的授权代码
  • 例如,浏览器地址栏中的URL字符串将类似于:
https://www.amazon.com/?code=xxxxxxxxxxxxxxxxxxx&scope=cpc_advertising%3Acampaign_management

步骤5:调用授权URL以请求授权和刷新令牌

  • 要检索授权和刷新令牌,请选择与步骤1中使用的URL相同区域的授权URL。URL为:
区域Authorization URL
North America (NA)https://api.amazon.com/auth/o2/token
Europe (EU)https://api.amazon.co.uk/auth/o2/token
Far East (FE)https://api.amazon.co.jp/auth/o2/token

接下来,构造API调用以检索授权和刷新令牌。该调用具有以下查询参数:

参数名称描述
grant_typeMust be authorization_code.
codeThe authorization code retrieved in step 4.
redirect_uriOne of the values from the consent privacy notice URL field. Recall that you retrieved this value in the prerequisites section of this document.
client_idThe Client ID value that you retrieved in the prerequisites section of this document.
client_secretThe Client Secret value that you retrieved in the prerequisites section of this document.
  •  API调用需要以下标头:
Content-Type:application/x-www-form-urlencoded
charset=UTF-8
  • 例如,要使用诸如cURL之类的工具检索授权和刷新令牌,请在以下请求中替换您的值:
curl  \
    -X POST \
    -H "Content-Type:application/x-www-form-urlencoded;charset=UTF-8" \
    --data "grant_type=authorization_code&code=AUTH_CODE&redirect_uri=YOUR_RETURN_URL&client_id=YOUR_CLIENT_ID&client_secret=YOUR_SECRET_KEY" \
    https://api.amazon.com/auth/o2/token

 此请求的响应是具有以下结构的JSON对象:

字段名描述
access_tokenThe authorization token.
refresh_tokenThe refresh token.
token_typeThe type of OAuth 2.0 token. Always set to bearer.
expires_inThe length of time until the authorization token expires, in seconds.
  •  例如:
{
    "access_token": "",
    "refresh_token": "",
    "token_type": "bearer",
    "expires_in": 3600
}
  • 请注意,授权令牌的有效期为60分钟,并且过期后必须使用刷新令牌进行刷新。刷新令牌不会过期。
  • 如下使用刷新令牌,将您的值替换为以下请求:
curl \                                                                                                                                                        
    -X POST \
    -H "Content-Type:application/x-www-form-urlencoded;charset=UTF-8" \
    --data "grant_type=refresh_token&client_id=YOUR_CLIENT_ID&refresh_token=YOUR_REFRESH_TOKEN&client_secret=YOUR_CLIENT_SECRET" \
    https://api.amazon.com/auth/o2/token
  • 此请求的响应与上面的响应相同。
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值