【问题标题】:Downloading Reports in Amazon Advertising API在亚马逊广告 API 中下载报告
【发布时间】:2021-03-12 07:08:04
【问题描述】:

我获得了报告 ID,使用报告 ID 我可以获得 S3 可下载链接。但是当我尝试使用它显示的链接时 - 未经授权访问。

【问题讨论】:

标签: amazon amazon-advertising-api


【解决方案1】:

您需要对下载链接执行 GET 请求。 URL 也需要身份验证,因此也必须传递授权标头。

编辑我正在添加一个我创建的函数,用于下载 GZipped 文件并提取其中的 Json,以防它帮助其他人:

import requests
import gzip
import json
import io

def report_download():
    req = requests.get(url, headers=headers)
    response = req.content
    zip_file = io.BytesIO(response)
    with gzip.open(zip_file, 'rb') as f: 
        file_content = f.read() 

    json_data = json.loads(file_content)
    with open("filename.json", "w") as outfile: 
        json.dump(json_data, outfile)

【讨论】:

  • 谢谢阿方索。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多