如何使用Python获取TikTok广告数据

huangapple go评论103阅读模式
英文:

How to fetch tiktok ads data using python

问题

我需要从TikTok获取广告系列(Campaign)、广告组(Ad Group)和广告(Ad)的数据,以下是我尝试过的代码:

import requests

url = "https://business-api.tiktok.com/open_api/v1.3/campaign/get/"

access_token = "your_access_token"

headers = {
    "Authorization": f"Bearer {access_token}"
}

response = requests.get(url, headers=headers)

if response.status_code == 200:
    print(response.json()) 
else:
    print(f"无法获取广告系列。状态码:{response.status_code}")
    print(None)

但是出现了以下错误:

{'code': 40104, 'message': 'Access token is null, you should set it in http header with key Access-Token.', 'request_id': '', 'data': {}}
英文:

I need to fetch data from tiktok for Campaign, Ad Group and Ad,
this is what I tried

import requests

url = "https://business-api.tiktok.com/open_api/v1.3/campaign/get/"

access_token = "your_access_token"

headers = {
    "Authorization": f"Bearer {access_token}"
}

response = requests.get(url, headers=headers)

if response.status_code == 200:
    print(response.json()) 
else:
    print(f"Failed to fetch ad campaigns. Status code: {response.status_code}")
    print(None)

But this is giving error as below

{'code': 40104, 'message': 'Access token is null, you should set it in http header with key Access-Token.', 'request_id': '', 'data': {}}

答案1

得分: 1

你的标头错误(正如错误信息中所指出的),应该是:

headers = {
    "Access-Token": "your_access_token"
}

官方文档链接:https://ads.tiktok.com/marketing_api/docs?id=1739315828649986

英文:

Your header is wrong (as it also says in the error), it has to be:

headers = {
    "Access-Token": "your_access_token"
}

Official documentation: https://ads.tiktok.com/marketing_api/docs?id=1739315828649986

huangapple
  • 本文由 发表于 2023年7月31日 18:47:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76802879.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定