EmilioBarradas / tiktok-app-api

🎵 Unofficial TikTok Node.js API
130 stars 21 forks source link

API returns empty data #14

Closed isAlmogK closed 3 years ago

isAlmogK commented 3 years ago

I'm seeing that at some point the API is returning an empty array and no data? Is this something on TikTok blocking the API calls its showing status 200 so its going threw

Screen Shot 2020-12-10 at 8 05 36 PM
isAlmogK commented 3 years ago

This might have been me trying to pull data with a count over 100, not 100%

EmilioBarradas commented 3 years ago

It may be TikTok blocking the calls. They usually never send out anything other than 200 level codes, and include any error message in the body of their response.

isAlmogK commented 3 years ago

Yea looks fine closing this

isAlmogK commented 3 years ago

So this is happing again and I'm sending the correct count

isAlmogK commented 3 years ago

So been trying to debug this but it does look like it's returning an empty array based on what I think it might have something to do withgetTrendingVideos() is collecting all data.

This is my code

async function getTreadingMusic(data) {

    // For API results
    /*
     cursor: string,
     count: init
    */
    console.log(data);
    const options = {
      cursor: data.cursor,
      count: data.count,
    };

    tiktokApp = await tiktok();

    //
    const iterator = tiktokApp.getTrendingVideos(options);
    const videosResult = await iterator.next();
    const trendingVideos = videosResult.value;

    console.log(trendingVideos);

  const audio = trendingVideos.map(v => {
    let selectedData = { playCount: v.likeCount, commentCount: v.commentCount, shareCount: v.shareCount, audio: v.audio };
    return selectedData;
  });

    console.log(audio);
    return audio;
}

and you can see from the screenshot from the console log its empty

Screen Shot 2020-12-11 at 2 39 48 AM
EmilioBarradas commented 3 years ago

It seems like TikTok changed the way they paginate the trending page, therefore the count feature is currently broken. I'll look into it.

EmilioBarradas commented 3 years ago

Their response body for the trending videos endpoint always returns a minCursor and maxCursor values of 1 regardless of the input cursor value, which breaks the pagination feature of getTrendingVideos. This seems to work fine for getUploadedVideos() so I think it might be an issue on their end.

isAlmogK commented 3 years ago

Funny I would open a ticket or bug report for that but they don't have an official API :) do you have any suggestions? I guess I should just leave the Cursor at 0 and in the next call move to it 1?

isAlmogK commented 3 years ago

So it's not working at all right now, I updated the package. Are you using the https://m.tiktok.com/node/share/discover API request?

isAlmogK commented 3 years ago

Ok, I see you're using the item list, I'm not seeing how they are doing there load more on the website. I'm not seeing anything in the request headers that would set the pagination. The only thing I see changing is the _signature: _02B4Z6wo00901YqtIoQAAICDn-lb5kXjMKmKrCYAAD2C4e between each call

isAlmogK commented 3 years ago

@EmilioBarradas can API let me causing this?

EmilioBarradas commented 3 years ago

Their API endpoint requires a minCursor and maxCursor parameter that is supposedly the starting position for the videos of the request, but specifying any minCursor and maxCursor will always result in the first subset of videos from the trending page. For this reason, the cursor property of the SearchOptions object will not change what videos are retrieved. I'll try looking further into this tomorrow.

isAlmogK commented 3 years ago

Yea so I want back to just sending 0 and 30 and still got an empty array back so I think there is something wrong.

isAlmogK commented 3 years ago

So its working now did you make any changes ?

isAlmogK commented 3 years ago

@EmilioBarradas I think I found the issue when looking at a python package - https://github.com/davidteather/TikTok-Api/issues/417

Since TikTok changed their API you need to use the custom_verifyFp option. In your web browser you will need to go to TikTok, Log in and get the s_v_web_id value.

Either way, this will not really work "Your custom verifyFp is probably invalid you can generate a new verifyFp here but this seems to have a cooldown and browser fingerprinting so it's not always valid."

The python package did work around not sure it works. But I think the direction might be scrapping the data which I'm looking into

isAlmogK commented 3 years ago

@EmilioBarradas if you can add custom_verifyFp option that would be great my plan is to only make the API once a day or once every hour and save the data into a DB

EmilioBarradas commented 3 years ago

I have not made any changes yet, so if it started to work again, it might be TikTok blocking subsequent requests. The _verifyFp parameter is not required for the trending page endpoint, nor does it fix the pagination issues, unfortunately.

isAlmogK commented 3 years ago

Is the captcha they added required

isAlmogK commented 3 years ago

I'm closing this as its a tiktok thing