TobyG74 / tiktok-api-dl

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

"Cannot read property 'responseUrl' of undefined" #5

Closed happer64bit closed 1 year ago

happer64bit commented 1 year ago

I am attempting to create a TikTok video downloader using your library. The route.params.video_url is set to https://www.tiktok.com/@devslopes/video/7276699914241985835?is_from_webapp=1&sender_device=pc.

The issue I'm encountering only occurs when I execute the function in a React Native app. It does not occur when I run a script like node index.js. Below are the code examples for both scenarios:

Node.js Script:

const TiktokDL = require("@tobyg74/tiktok-api-dl");

TiktokDL("https://www.tiktok.com/@devslopes/video/7276699914241985835?is_from_webapp=1&sender_device=pc").then((result) => {
    console.log(result);
});

React Native Code:

import { Dimensions, View, Image } from 'react-native';
import { ActivityIndicator, Text } from 'react-native-paper';
import { useEffect, useState } from 'react';
import { DLResult } from '@tobyg74/tiktok-api-dl/lib/types';
import { TiktokDL } from '@tobyg74/tiktok-api-dl';

export default function ({ route, navigation }: any) {
    const [isLoading, setIsLoading] = useState<boolean>(true);
    const [data, setData] = useState<DLResult | null | void>(null);

    useEffect(() => {
        TiktokDL(route.params.video_url).then((result) => {
            setIsLoading(false);
            setData(result);
            console.log(result);
        });
    }, []);

    return (
        <View style={{
            height: Dimensions.get("window").height,
            backgroundColor: "#15131A"
        }}>
            <View style={{
                marginTop: 30,
                padding: 20
            }}>
                {isLoading ? <ActivityIndicator size={"large"} /> : null}
                {!isLoading && data && data.result != null ? (
                    <>
                        <View>
                            <View style={{
                                display: "flex",
                                flexDirection: "row",
                                justifyContent: "space-between",
                                alignItems: "center"
                            }}>
                                <View>
                                    <Image
                                        source={{
                                            uri: data.result.cover?.toString()
                                        }}
                                    />
                                </View>
                                <Text style={{ color: "#fff" }}>{data.result.description}</Text>
                            </View>
                        </View>
                    </>
                ) : null}
                {data?.status == "error" && (
                    <Text style={{ color: "red", fontSize: 16 }}>{data?.message}</Text>
                )}
            </View>
        </View>
    );
}

The issue I'm facing is titled "Cannot read property 'responseUrl' of undefined."

TobyG74 commented 1 year ago

That's an error in retrieving the Video ID, Try using the Axios GET method to get the ID of the video

https://github.com/TobyG74/tiktok-api-dl/blob/35d341ecf8b4ca8bc88ca2a5cc3986f5c9e16a8c/src/utils/index.ts#L12