freeewillie
freeewillie

Reputation: 63

TikTok query videos research API - getting search ID is invalid or expired

I have a research account with TikTok and am using their query videos API. Documentation here.

I am trying to retrieve all videos from a single day with a search and that takes multiple calls, so after my first API call I use the cursor and search_id parameters in the next call as instructed in the API docs. However I always get an error that Search Id 7414696757969294378 is invalid or expired (with the relevant search ID).

Looks like other folks have run into this issue here. Unfortunately the TikTok support team has not gotten back to me after reaching out, so any assistance would be appreciated!

First query videos call

Request body: {
    "method": "POST",
    "url": "https://open.tiktokapis.com/v2/research/video/query/?fields=id%2Cvideo_description%2Ccreate_time%2Cregion_code%2Cshare_count%2Cview_count%2Clike_count%2Ccomment_count%2Cfavorites_count%2Cmusic_id%2Chashtag_names%2Cusername%2Ceffect_ids%2Cplaylist_id%2Cvoice_to_text",
    "headers": {
        "User-Agent": "python-requests/2.32.3",
        "Accept-Encoding": "gzip, deflate",
        "Accept": "*/*",
        "Connection": "keep-alive",
        "Authorization": {omitted},
        "Content-Type": "application/json",
        "Content-Length": "206"
    },
    "body": "{\"query\": {\"and\": [{\"operation\": \"EQ\", \"field_name\": \"hashtag_name\", \"field_values\": [\"election\"]}]}, \"start_date\": \"20230101\", \"end_date\": \"20230101\", \"max_count\": 5, \"search_id\": \"\", \"cursor\": 0}"
}
INFO:tik_tok_api:Response body: {
    "data": {
        "cursor": 5,
        "has_more": true,
        "search_id": "7414696757969294378",
        "videos": [<list of video objects>]
    },
    "error": {
        "code": "ok",
        "message": "",
        "log_id": "2024091504190332DAC901505CAC3E3B2E"
    }
}

Second query videos call

INFO:tik_tok_api:Request body: {
    "method": "POST",
    "url": "https://open.tiktokapis.com/v2/research/video/query/?fields=id%2Cvideo_description%2Ccreate_time%2Cregion_code%2Cshare_count%2Cview_count%2Clike_count%2Ccomment_count%2Cfavorites_count%2Cmusic_id%2Chashtag_names%2Cusername%2Ceffect_ids%2Cplaylist_id%2Cvoice_to_text",
    "headers": {
        "User-Agent": "python-requests/2.32.3",
        "Accept-Encoding": "gzip, deflate",
        "Accept": "*/*",
        "Connection": "keep-alive",
        "Authorization": {omitted},
        "Content-Type": "application/json",
        "Content-Length": "225"
    },
    "body": "{\"query\": {\"and\": [{\"operation\": \"EQ\", \"field_name\": \"hashtag_name\", \"field_values\": [\"election\"]}]}, \"start_date\": \"20230101\", \"end_date\": \"20230101\", \"max_count\": 5, \"search_id\": \"7414696757969294378\", \"cursor\": 5}"
}
INFO:tik_tok_api:Response body: {
    "error": {
        "code": "invalid_params",
        "message": "Search Id 7414696757969294378 is invalid or expired",
        "log_id": "2024091504190471DF3E7577323038D625"
    }
}

Thank you!

Upvotes: 0

Views: 270

Answers (1)

gidzel
gidzel

Reputation: 1

I also ran into this problem. Until it gets fixed by tiktok you can try to repeat the request several times until it gets handled. For me it takes 2-5 retries per request until it gets handled.

Upvotes: 0

Related Questions