gpt4 book ai didi

python - 我们如何下载亚马逊广告 Api 报告?

转载 作者:行者123 更新时间:2023-12-02 03:21:21 26 4
gpt4 key购买 nike

我正在沙箱环境中工作,我正在尝试下载基于 https://advertising.amazon.com/API/docs/v2/reference/reports 的报告问题是下载的报告是空的。里面不包含任何数据。我们如何从亚马逊广告API下载报告?

我按照描述的步骤操作:https://gist.github.com/dbrent-amazon/ca396a63c1670ee0ec83aad26b0ce55b

最佳答案

这是一个适用于我的使用 python 和请求的脚本,请确保:

  1. 创建广告系列、adGroupd 和关键字
  2. 使用正确的指标创建报告
  3. 确保您有可在报告中查看的实际数据
  4. 确保报告日期正确
import requests

version = 'v2'
advertise = 'sp'

headers = {
"Authorization": f"Bearer {token.access}",
"Amazon-Advertising-API-ClientId": AmazonSecurityProfile.ClientID,
"Content-Type": "application/json",
}

class urls:
class api:
test = 'https://advertising-api-test.amazon.com'

# create report
recordType = "keywords"
r = requests.post(
f'{urls.api.test}/{version}/{advertise}/{recordType}/report',
json={
# "campaignType": "sponsoredProducts",
"segment": "query",
"reportDate": '20201025', #YYYYMMDD
"metrics": ",".join([
"campaignName",
"campaignId",
"campaignStatus",
"campaignBudget",
"clicks",
"cost",
"attributedConversions1d",
"attributedConversions7d",
"attributedConversions1dSameSKU",
"attributedConversions7dSameSKU",
"attributedUnitsOrdered1d",
"attributedUnitsOrdered7d",
"attributedSales1d",
"attributedSales7d",
"attributedSales1dSameSKU",
"attributedSales7dSameSKU",
"attributedUnitsOrdered1dSameSKU",
"attributedUnitsOrdered7dSameSKU",
"adGroupName",
"adGroupId",
"keywordText",
"keywordId",
"matchType",
"impressions",
]),
},
headers=headers,
)
r.raise_for_status()
r = r.json()
print(r)
reportId = r["reportId"]

while r['status'] == 'IN_PROGRESS':
r = requests.get(
f'{urls.api.test}/{version}/reports/{reportId}',
headers=headers,
)
r = r.json()
print(r)

assert r['status'] == 'SUCCESS'

r = requests.get(
r["location"],
headers=headers,
)
print(r)

关于python - 我们如何下载亚马逊广告 Api 报告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54665341/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com