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

cs7cruho  于 2023-08-08  发布在  Python
关注(0)|答案(1)|浏览(111)

我需要从tiktok中获取活动数据,广告组和广告,这是我试过的

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)

字符串
但这会产生如下误差

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

dfddblmv

dfddblmv1#

你的头是错误的(因为它也在错误中说),它必须是:

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

字符串
正式文件:https://ads.tiktok.com/marketing_api/docs?id=1739315828649986

相关问题