Tiktok api /user/info endpoint

Question:

Edit: Since this question is getting a good amount of views, I’d like to let you all know before you waste hours of your life on the upload endpoint that it currently requires you to manually click confirm in the app. So it doesn’t allow you to fully automate uploads. To anyone which this saves time, you’re welcome 🙂

Currently trying to implement the TikTok api into one of my projects. However having a few difficulties with a specific endpoint. Not sure if its an error on my part or on Tiktoks.

Upon making the below request I am recieving an invalid request body error message. I have followed their documentation to the T so unsure why this is happening?

https://developers.tiktok.com/doc/login-kit-user-info-basic

    data = {
        "access_token": access_token,
        "open_id": open_id,
        "fields": [
            "open_id",
            "union_id",
            "avatar_url",
            "avatar_url_100",
            "avatar_url_200",
            "avatar_large_url",
            "display_name"
        ]
    }

    user_info = requests.post("https://open-api.tiktok.com/user/info/", data=data)

    print(user_info.json())
{'data': {}, 'error': {'code': 6007055, 'log_id': '', 'message': 'invalid request body'}}
Asked By: jaal kamza

||

Answers:

Use json parameter instead of data

import requests
data = {
        "access_token": access_token,
        "open_id": open_id,
        "fields": [
            "open_id",
            "union_id",
            "avatar_url",
            "avatar_url_100",
            "avatar_url_200",
            "avatar_large_url",
            "display_name"
        ]
    }

user_info = requests.post("https://open-api.tiktok.com/user/info/", json=data)

print(user_info.json())
Answered By: F.Hoque
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.