youtube / api-samples

Code samples for YouTube APIs, including the YouTube Data API, YouTube Analytics API, and YouTube Live Streaming API. The repo contains language-specific directories that contain the samples.
5.49k stars 2.97k forks source link

How can I get all the video name from an playlist with the google api? I #310

Open TheEpicFace007 opened 3 years ago

TheEpicFace007 commented 3 years ago

How can I get all the video name from an playlist with the google api? I already tried to do it with diffrent part parameter and it didn't work. I am using the node js version of the google api Here is my code: ```js function GetYtbPlaylistId(PlaylistLink) { const PlaylistIDRegex = /list=(.+)/ig; if (!PlaylistIDRegex.test(PlaylistLink)) return; let ID = PlaylistIDRegex.exec(PlaylistLink); ID = PlaylistIDRegex.exec(PlaylistLink); return ID[1]; }

export async function YoutubeToSpotify(Playlist) { Playlist = GetYtbPlaylistId(Playlist); const PlaylistItem = await google.youtube("v3").playlists.list({ auth: config.default.GoogleApiKey, key: config.default.GoogleApiKey,

    part: ["id", "contentDetails", "status"],
    id: [Playlist],
    maxResults: 500,

}).catch(reason => Promise.reject(reason));

/*     google.youtube("v3").playlistItems.list({
        key: config.default.GoogleApiKey,

        part: ["id"]
    }); */
console.log(PlaylistItem);

}



YoutubeToSpotify("https://www.youtube.com/playlist?list=PL8CB7943AB56938F8")
    .catch((reason) => {
        // console.error(reason.response.data.error ?? reason.response);
        console.log(reason);
    });
CavalcanteLucas commented 3 years ago

After obtained each video's ID from your PlaylistItem request, you'll have to fetch for each video data, and then get the video's title.