广告API对接总体流程>>>
下图中出现的相关URL,是以北美站为例
亚马逊广告各实体间关系>>>
1. 广告API对接准备
1.1 申请亚马逊开发者帐号和广告API访问帐号
(略)API申请如有问题,可以入群交流。
1.2 生成访问广告API的access token
1.3 生成访问授权码(generate an authorization code)
说明:访问授权码是为了生成访问广告api时的access token
1) Paste the authorization URL determined above into your browser's address bar. Navigate to the URL.
地址如下:
https://www.amazon.com/ap/oa?client_id=YOUR_LWA_CLIENT_ID&scope=advertising::campaign_management&response_type=code&redirect_uri=YOUR_RETURN_URL
2) Sign in using the Amazon account that has permission to access Amazon Ads services for the products you want to advertise. (This is an Advertiser account, which may not be the same as the Amazon Developer account you used to create the LwA client.)
拥有广告访问权限亚马逊帐号访问上述地址,在登录店铺情况下,将出现下图授权:
3) You will be redirected to a consent form:
4)You will be redirected to the redirect_uri that you specified previously, with query parameters appended to the URL. Copy the address from your browser's address bar, and note the value of the code parameter (the xxxx in the example below):
Amazon.comhttps://www.amazon.com/?code=xxxxxxxxxxxxxxxxxxx&scope=advertising%3A%3Acampaign_management
复制下code的值,该值就是 authorization code
1.4 生成访问授权码(generate an authorization code)
生成access token和 refresh token(Create access and refresh tokens)
1)、Post 提交如下报文
地址:https://api.amazon.com/auth/o2/token
参数:
grant_type=authorization_code&code=AUTH_CODE&redirect_uri=YOUR_RETURN_URL&client_id=YOUR_CLIENT_ID&client_secret=YOUR_SECRET_KEY
说明:AUTH_CODE就是
Amazon.comhttps://www.amazon.com/?code=xxxxxxxxxxxxxxxxxxx&scope=advertising%3A%3Acampaign_management
里的code值,content-type需要设置为: application/x-www-form-urlencoded;charset=UTF-8
Parameter | Description |
grant_type | Must be authorization_code. |
code | The authorization code retrieved in step 4. Note this code expires after 5 minutes. |
redirect_uri | One of the values in the Allowed Return URLs field in your Login with Amazon account. |
client_id | The Client ID of your Login with Amazon account. |
client_secret | The Client Secret of your Login with Amazon account. |
2)、返回access token 和 refresh token(Access token response)
范例:
{
"access_token": "Atza|XXXXXXXXXXXX",
"refresh_token": "Atzr|XXXXXXXXXXXX",
"token_type": "bearer",
"expires_in": 3600
}
参数说明:
Field | Description |
access_token | The access token. |
refresh_token | The refresh token. |
token_type | The type of OAuth 2.0 token. Always set to bearer. |
expires_in | The length of time until the access token expires, in seconds. |
- Note that access tokens are valid for 60 minutes. A new access token can be generated at any time using the refresh token. Refresh tokens do not expire.
- access token 有效期是60分钟,refresh token 没有有效期,通过 refresh token可生成 access token.
3)、用refresh token换取 access token
地址:https://api.amazon.com/auth/o2/token
参数:
grant_type=refresh_token&client_id=YOUR_CLIENT_ID&refresh_token=YOUR_REFRESH_TOKEN&client_secret=YOUR_CLIENT_SECRET
说明:YOUR_REFRESH_TOKEN就是步骤2获取到的refresh_token.
content-type需要设置为: application/x-www-form-urlencoded;charset=UTF-8
2. 其他资源:
2.1 访问广告API权限
详见:
Amazon Advertising Advanced Tools Centerhttps://advertising.amazon.com/API/docs/en-us/concepts/permissions
2.2 访问广告API限制
详见:Amazon Advertising Advanced Tools Centerhttps://advertising.amazon.com/API/docs/en-us/concepts/rate-limiting
访问受限,返回429错误代码,同时在http头里会包含Retry-After字段,用于指示此值对应的秒数后再请求。
2.3 开发人员应注意事项
详见:Amazon Advertising Advanced Tools Center
2.4 沙箱测试
详见:Amazon Advertising Advanced Tools Center
例子:
curl \
-X PUT \
-H "Content-Type:application/json" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Amazon-Advertising-API-ClientId: YOUR_CLIENT_ID" \
--data '{"countryCode":"US"}' \
https://advertising-api-test.amazon.com/v2/profiles/register