4
votes

I've followed the instructions in this Google video and elsewhere to:

  • connect to the v3 API using a static API key
  • get the playlist ID for uploads for a channel, using the legacy channel ID (e.g. "GoogleDevelopers")
  • use the playlistItems endpoint for that playlist to retrieve the list of videos uploaded to that YouTube account.

The first two stages work and I'm able to get the channel/playlist ID, but playlistItems is returning playlistNotFound every time (I've tested it with several different YouTube accounts.)

I've been trying to carefully check for typos - I can't spot anything wrong with the requests.

Any ideas, or can anyone reproduce the problem?

Example API call (using the GoogleDevelopers channel as shown in their video) - you'll need to generate your own API key to test this:

https://www.googleapis.com/youtube/v3/channels?key=[myAPIkey]&forUsername=GoogleDevelopers&part=id

Response:

{
 "kind": "youtube#channelListResponse",
 "etag": "\"IHLB7Mi__JPvvG2zLQWAg8l36UU/9Uu_LJKSiIBlJOBZoZLkKcjhUUE\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 5
 },
 "items": [
  {
   "kind": "youtube#channel",
   "etag": "\"IHLB7Mi__JPvvG2zLQWAg8l36UU/JgZIwrlCnsd1wzjssCxaCFp8mRU\"",
   "id": "UC_x5XG1OV2P6uZZ5FSM9Ttw"
  }
 ]
}

Attempting to get the first video in the playlist:

https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=1&key=[myAPIkey]&playlistId=UC_x5XG1OV2P6uZZ5FSM9Ttw

{
 "error": {
  "errors": [
   {
    "domain": "youtube.playlistItem",
    "reason": "playlistNotFound",
    "message": "Not Found",
    "locationType": "parameter",
    "location": "playlistId"
   }
  ],
  "code": 404,
  "message": "Not Found"
 }
}

Note: I generated a server key, because this is going to run on a server. But I'm testing in a browser (with the IP addresses whitelisted.) This shouldn't cause any issues should it? (no auth errors so far.)

1
Hey @William, even im facing this same issue. Were you able to resolve? - Adithya
@Adithya no - what I ended up doing was using the RSS feed: youtube.com/feeds/… – I did manage to get the v3 data API working to retrieve details of a specific video though, in the form: googleapis.com/youtube/v3/… - William Turrell

1 Answers

3
votes

William, what you've used as a playlist id is a channel id, to get a list of playlists with ids you need to add contentDetails to part parameter.

https://www.googleapis.com/youtube/v3/channels?part=contentDetails&maxResults=50&forUsername=GoogleDevelopers&key=<APIKEY>

Response:

{
  kind: "youtube#channelListResponse",
  etag: ""iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/rGUGLTaUoy_huV1Qfc0wvulpr7M"",
  pageInfo: {
    totalResults: 1,
    resultsPerPage: 50
  },
  items: [
    {
      kind: "youtube#channel",
      etag: ""iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/Il2dF5SRdky6_tqanN3hNuDyfxc"",
      id: "UC_x5XG1OV2P6uZZ5FSM9Ttw",
      contentDetails: {
        relatedPlaylists: {
          uploads: "UU_x5XG1OV2P6uZZ5FSM9Ttw"
        },
      googlePlusUserId: "111395306401981598462"
      }
    }
  ]
}

Then use "UU_x5XG1OV2P6uZZ5FSM9Ttw" as an uploads playlist so next call will look like that:

https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&maxResults=1&playlistId=UU_x5XG1OV2P6uZZ5FSM9Ttw&key=<APIKEY>

Response:

{
  kind: "youtube#playlistItemListResponse",
  etag: ""iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/AqAMzBB7CuVjpCKtQDHbbIvjtMU"",
  nextPageToken: "CAEQAA",
  pageInfo: {
    totalResults: 3761,
    resultsPerPage: 1
  },
  items: [{
    kind: "youtube#playlistItem",
    etag: ""iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/qjqde7mm3USo4TmUrxDN8KdbyaQ"",
    id: "UUj6hVp42BfAXGn9SkmnI_HudylmOycmdp",
    contentDetails: {
      videoId: "tjmRUgUca1g"
    }
  }]
}