Tiktok Direct post API - Redirect_URI issue

227 views Asked by At

I would like to get the authorization code from tiktok's API but everytime I face the same Error.

enter image description here

Auth 127.0.0.1 - - "GET /auth/ HTTP/1.1" 301
Response
https://www.tiktok.com/v2/auth/authorize/?client_key=<client_key>&scope=user.info.basic&response_type=code&redirect_uri=http%3A%2F%2F127.0.0.1%3A8080%2Fcallback%2F&state=344a13d1f932a73517ea31abaf98cd66&code_challenge=%7B%27d85aea26bf0fded67f98fa487aab480061ca0d00786dbd064399fe93d06b5704%27%7D&code_challenge_method=S256&error=invalid_request&error_type=redirect_uri

PS Ii am using staging keys not production keys.

RedirectURI 127.0.0.1 - - "GET /callback/ HTTP/1.1" 200 the same as the tiktok's app Redirect_uri

i made this code based on the tiktok's Doc Code

def getAuthorizationURL():
    AUTHORIZE_URL = 'https://www.tiktok.com/v2/auth/authorize/'

    csrf_state = secrets.token_hex(16)

    params = {
        'client_key': Auth.tiktok_client_key,
        'scope': 'user.info.basic',
        'response_type': 'code',
        'redirect_uri': Auth.tiktok_redirect_uri, #"http://127.0.0.1:8080/callback/"
        'state': csrf_state,
        'code_challenge':__generateRandomString(64),
        'code_challenge_method':'S256'    }

    url = AUTHORIZE_URL + '?' + urllib.parse.urlencode(params)
    
    return url

I contacted their support but they didn't respond yet and, unfortunately, I couldn't find anything online.

0

There are 0 answers