英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论