Getting all videos of a channel using youtube API

后端 未结 3 1370
醉酒成梦
醉酒成梦 2021-02-04 12:05

I want to get all videos of a single channel that i have its Id. The problem that I am getting only the channel informations. this is the link that I am using:

3条回答
  •  不思量自难忘°
    2021-02-04 12:30

    That link is for the now-retired V2 API, so it will not return any data. Instead, you'll want to use V3 of the API. The first thing you'll need to do is register for an API key -- you can do this by creating a project at console.developers.google.com, setting the YouTube data API to "on," and creating a public access key.

    Since you have your user channel ID already, you can jump right into getting the videos from it; note, however, that if you ever don't know the channel ID, you can get it this way:

    https://www.googleapis.com/youtube/v3/channels?part=snippet&forUsername={username}&key={YOUR_API_KEY}
    

    With the channel ID, you can get all the videos from the channel with the search endpoint, like this:

    https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId={channel id here}&maxResults=25&key={YOUR_API_KEY}
    

    In this case, ordering by date is the same as the old V2 parameter for ordering by "published."

    There are also a lot of other parameters you can use to retrieve videos while searching a channel; see https://developers.google.com/youtube/v3/docs/search/list for more details.

提交回复
热议问题