Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YouTube API v3 - List uploaded videos

How do I list the user's uploaded videos in the V3 api?

like image 317
efic1 Avatar asked Oct 17 '12 08:10

efic1


People also ask

Is YouTube data API v3 free?

Yes, using the YouTube API does not incur any monetary cost for the entity calling the API. If you go over your quota an 403 Error will be returned by the API.

How do I find my YouTube channel list?

You can see your channel's user and channel IDs in your advanced account settings on a computer or mobile browser. Sign in to YouTube. From the left menu, select Advanced settings. You'll see your channel's user and channel IDs.

How do I upload videos from the API?

# Call the API's videos.insert method to create and upload the video. # bytes, that will be uploaded at a time. Set a higher value for # reliable connections as fewer chunks lead to faster uploads. Set a lower # value for better recovery on less reliable connections.

How to get a list of YouTube videos of Your Channel?

In this article, we study how to use YouTube API to get a list of YouTube videos of your channel. A user can see all their videos on the YouTube website itself. But if you want to share the video list with someone else then you have to keep this data offline. On the other hand, some users may want to display a video list on their website.

How to integrate YouTube Data API in your project?

You will see list of Google APIs. Enable YouTube Data API. Click on the Credentials. Select API key under Create credentials. Copy the API key. We will need it in a moment. Once you are ready with the API key, create 3 files in your project.

How to create an API key for YouTube?

Follow the steps below to create an API Key. Create a new project. You can select existing project also. Type a name of your project. Google Console will create unique project ID. After creating a project, it will appear on top of the left sidebar. Click on Library. You will see list of Google APIs. Enable YouTube Data API.


2 Answers

If you are using the client then Greg's answer is correct. To do the same thing with basic requests you make the following 2 requests:

  1. GET https://www.googleapis.com/youtube/v3/channels

    with parameters:

    part=contentDetails
    mine=true
    key={YOUR_API_KEY}
    

    and header:

    Authorization:  Bearer {Your access token}
    

    From this you will get a JSON response like so:

    {
     "kind": "youtube#channelListResponse",
     "etag": "\"some-string\"",
     "pageInfo": {
      "totalResults": 1,
      "resultsPerPage": 1
     },
     "items": [
      {
       "id": "some-id",
       "kind": "youtube#channel",
       "etag": "\"another-string\"",
       "contentDetails": {
        "relatedPlaylists": {
         "likes": "channel-id-for-your-likes",
         "favorites": "channel-id-for-your-favorites",
         "uploads": "channel-id-for-your-uploads",
         "watchHistory": "channel-id-for-your-watch-history",
         "watchLater": "channel-id-for-your-watch-later"
        }
       }
      }
     ]
    }
    

    From this you want to parse out the "uploads" channel-id.

  2. GET https://www.googleapis.com/youtube/v3/playlistItems

    with parameters:

    part=snippet
    maxResults=50
    playlistId={YOUR_UPLOAD_PLAYLIST_ID}
    key={YOUR_API_KEY}
    

    and headers:

    Authorization:  Bearer {YOUR_TOKEN}
    

    From this you will receive a JSON response like the following:

    {
     "kind": "youtube#playlistItemListResponse",
     "etag": "\"some-string\"",
     "pageInfo": {
      "totalResults": 1,
      "resultsPerPage": 50
     },
     "items": [
      {
    
       "id": "some-id",
       "kind": "youtube#playlistItem",
       "etag": "\"another-string\"",
       "snippet": {
        "publishedAt": "some-date",
        "channelId": "the-channel-id",
        "title": "video-title",
        "thumbnails": {
         "default": {
          "url": "thumbnail-address"
         },
         "medium": {
          "url": "thumbnail-address"
         },
         "high": {
          "url": "thumbnail-address"
         }
        },
        "playlistId": "upload-playlist-id",
        "position": 0,
        "resourceId": {
         "kind": "youtube#video",
         "videoId": "the-videos-id"
        }
       }
      }
     ]
    }
    

With this method you should be able to get the info using any language or even just curl. If you want more than the first 50 results, then you will have to do multiple queries using the second request and pass in page requests. More on this can be read at: http://developers.google.com/youtube/v3/docs/playlistItems/list

like image 178
Chad Befus Avatar answered Oct 08 '22 12:10

Chad Befus


The first step is getting the channel id for that user. We can do this with request to the Channels service. Here's a JS example.

var request = gapi.client.youtube.channels.list({
  // mine: true indicates that we want to retrieve the channel for the authenticated user.
  mine: true,
  part: 'contentDetails'
});
request.execute(function(response) {
  playlistId = response.result.channels[0].contentDetails.uploads;
});

Once we get the playlist id we can use that to query for the list of uploaded videos from the PlaylistItems service.

var request = gapi.client.youtube.playlistItems.list({
  playlistId: playlistId,
  part: 'snippet',
});
request.execute(function(response) {
  // Go through response.result.playlistItems to view list of uploaded videos.
});
like image 34
Greg Schechter Avatar answered Oct 08 '22 14:10

Greg Schechter