0

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': {}}
gourav
  • 33
  • 7
  • I'm sorry, but did you read the error message? – AKX Jul 31 '23 at 10:57
  • Where the error message says `Access token is null, you should set it in http header with key Access-Token.`, what do you think this means? In particular, what do you suppose the `with key Access-Token` part might be trying to tell you about the header? Aside from that, did you try reading the documentation? – Karl Knechtel Aug 08 '23 at 06:53

1 Answers1

1

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

Cow
  • 2,543
  • 4
  • 13
  • 25
  • 1
    @gourav In your TikTok business account, go to Users > Members, and under the Advertiser account, you can see the ID. – Cow Jul 31 '23 at 11:17