TobyG74 / tiktok-api-dl

Scrapper for download Video, Image, Music from Tiktok
Apache License 2.0
69 stars 18 forks source link

Failed to fetch tiktok data. Make sure your tiktok url is correct! #22

Closed exx0dusss closed 1 month ago

exx0dusss commented 3 months ago

Hello, author. Recently, I have started getting the following error for the API v1. Any suggestions on what the problem may be? Would really appreciate the issue to be resolved. Thanks in advance.

image image
AdeoNeriola commented 3 months ago

These changes to params.js worked for me. The hardest part is getting your personal iid. There's some methods with modded tiktok on android. Maybe the already presented iid will work with the new parameters, but I haven't tried it.

const _tiktokApiParams = (args) => {
    return {
        ...args,
        device_platform: 'android',
        os: 'android',
        ssmix: 'a',
        _rticket: Date.now(),
        cdid: "00000000-0000-0000-0000-000000000000", //CHANGE TO RANDOM UID
        channel: 'googleplay',
        aid: "1233",
        app_name: "musical_ly",
        version_code: "340303",
        version_name: "34.3.3",
        manifest_version_code: "2023403030",
        update_version_code: "2023403030",
        ab_version: "34.3.3",
        resolution: '1080*2400',
        dpi: 420,
        device_type: 'Pixel 7',
        device_brand: 'Google',
        language: 'en',
        os_api: '34',
        os_version: '14',
        ac: 'wifi',
        is_pad: '0',
        current_region: 'US',
        app_type: 'normal',
        sys_region: 'US',
        last_install_time: 1689872087,
        timezone_name: 'America/New_York',
        residence: 'US',
        app_language: 'en',
        timezone_offse: '-14400',
        host_abi: 'armeabi-v7a',
        locale: 'en',
        ac2: 'wifi5g',
        uoo: '1',
        carrier_region: 'US',
        op_region: 'US',
        build_number: "34.3.3",
        region: 'US',
        ts: Date.now() / 1000,
        iid: "YOUR IID HERE", //CHANGE TO YOUR IID
        device_id: "YOUR DEVICE ID HERE", //CHANGE TO YOUR DEVICE ID
        openudid: randomChar("0123456789abcdef", 16)
    };
};
heismauri commented 3 months ago

These changes to params.js worked for me. The hardest part is getting your personal iid. There's some methods with modded tiktok on android. Maybe the already presented iid will work with the new parameters, but I haven't tried it.

const _tiktokApiParams = (args) => {
    return {
        ...args,
        device_platform: 'android',
        os: 'android',
        ssmix: 'a',
        _rticket: Date.now(),
        cdid: "00000000-0000-0000-0000-000000000000", //CHANGE TO RANDOM UID
        channel: 'googleplay',
        aid: "1233",
        app_name: "musical_ly",
        version_code: "340303",
        version_name: "34.3.3",
        manifest_version_code: "2023403030",
        update_version_code: "2023403030",
        ab_version: "34.3.3",
        resolution: '1080*2400',
        dpi: 420,
        device_type: 'Pixel 7',
        device_brand: 'Google',
        language: 'en',
        os_api: '34',
        os_version: '14',
        ac: 'wifi',
        is_pad: '0',
        current_region: 'US',
        app_type: 'normal',
        sys_region: 'US',
        last_install_time: 1689872087,
        timezone_name: 'America/New_York',
        residence: 'US',
        app_language: 'en',
        timezone_offse: '-14400',
        host_abi: 'armeabi-v7a',
        locale: 'en',
        ac2: 'wifi5g',
        uoo: '1',
        carrier_region: 'US',
        op_region: 'US',
        build_number: "34.3.3",
        region: 'US',
        ts: Date.now() / 1000,
        iid: "YOUR IID HERE", //CHANGE TO YOUR IID
        device_id: "YOUR DEVICE ID HERE", //CHANGE TO YOUR DEVICE ID
        openudid: randomChar("0123456789abcdef", 16)
    };
};

Does that still work for you?

exx0dusss commented 3 months ago

I tried to change this data but nothing works. Also it is extremely hard to get device_id as I don't have any android/windows os to somehow get it.

AdeoNeriola commented 3 months ago

@heismauri @exx0dusss It worked for like a week and suddenly stopped 14 hours ago. So i guess they patched something again unfortunately.

exx0dusss commented 3 months ago

Any updates?

lean098 commented 2 months ago

I modified the code and added a cookie to the request, in addition to placing it inside an asyncRetry (async-retry).

I started to notice a certain delay after using it for a while, if anyone knows how to solve it in a better way, below is the code with the changes.

It's working, but it takes a long time.

axios .head(formatedUrl) .then(async ({ request, headers }) => { const cookie = headers?.["set-cookie"] ?.find((cookie) => cookie.startsWith("ttwid=")) ?.split(";")?.[0] ?? "";

    const { responseUrl } = request.res;
    const ID = responseUrl.match(/\d{17,21}/g);

    if (!ID || !ID?.length)
      return res.status(500).json({ error: "get awemeId error" });

    if (!cookie)
      return res.status(500).json({ error: "ttwid cookie not found" });

    const aweme_id = ID[0];

    let response = {} as AxiosResponse<any, any>;

    await asyncRetry(
      async () => {
        const res = await axios({
          url: tiktokapi(
            new URLSearchParams(
              withParams({
                aweme_id,
              })
            ).toString()
          ),
          method: "GET",
          headers: {
            Referer: formatedUrl,
            "User-Agent":
              "com.zhiliaoapp.musically/2022600030 (Linux; U; Android 7.1.2; es_ES; SM-G988N; Build/NRD90M;tt-ok/3.12.13.1)",
            Cookie: cookie,
          },
        });

        if (res?.status === 200) {
          if (res.data) {
            response = res;
            return response;
          }
        }

        throw new Error("Data is empty!");
      },
      { forever: true, minTimeout: 0, maxTimeout: 0 }
    );

    if (response?.status === 200) {
      const data = response.data?.aweme_list?.find(
        (v: { aweme_id: string }) => v.aweme_id === aweme_id
      );

      if (!data) return res.status(500).json({ error: "parse data error" });

      return res.status(200).json({
        ...parseTikTokData(data),
      });
    }
TobyG74 commented 2 months ago

Please try again guys, I've updated it. And the funny thing is that you only need to change the method in the request from "GET" to "OPTIONS" XD

exx0dusss commented 2 months ago

Now the error is different :(

{ status: 'error', message: 'Cannot convert argument to a ByteString because the character at index 512 has a value of 8230 which is greater than 255.' }

TobyG74 commented 2 months ago

is this tiktok downloader v1?

exx0dusss commented 2 months ago

Yes, it is. It is the most useful one for me

TobyG74 commented 2 months ago

Yes, it is. It is the most useful one for me

you can contact me via telegram or whatsapp, so i can help with more details