Search code examples
javayoutuberssgdata

Retrieving feeds (uploads) for YouTube user


Sometimes last year I could retrieve (publicly accessible) video feeds for a YouTube user by simply appending/uploads?alt=rss. e.g. http://gdata.youtube.com/feeds/base/users/NTVKenya gave http://gdata.youtube.com/feeds/base/users/NTVKenya/uploads?alt=rss. But this service is no longer available.

Now the recommended way, I guess, is to use GData library. However, using this service is giving me com.google.gdata.util.NoLongerAvailableException exception:

        YouTubeService service = new YouTubeService("service"); 
        ArrayList<String> urls = new ArrayList<String>();
        VideoFeed videoFeed = service.getFeed(new URL('http://gdata.youtube.com/feeds/base/users/NTVKenya'), VideoFeed.class);
        for (VideoEntry videoEntry : videoFeed.getEntries() ) {
            urls.add( videoEntry.getHtmlLink().getHref() );
        }

This gives:

        com.google.gdata.util.NoLongerAvailableException: No longer available
        <errors xmlns='http://schemas.google.com/g/2005'><error><domain>GData</domain><code>NoLongerAvailableException</code><internalReason>No longer available</internalReason></error></errors>

Where am I going wrong?

Thanks.


Solution

  • That was way harder than I expected!

    The crux is that you need a YouTube Developer API Key now. You can get your key at: https://console.developers.google.com

    enter image description here

    enter image description here

    Once I created an app and got my key, I tinkered around with the new V3 API found here: https://developers.google.com/youtube/v3/sample_requests

    And I was able to build a URL that seems to work... You may need to research and refine it a little more. Here's what I tried (replace MYAPIKEYHERE with your key): https://www.googleapis.com/youtube/v3/search?part=snippet&q=NTVKenya&order=viewCount&type=video&key=MYAPIKEYHERE

    And here's what it returned:

    {
     "kind": "youtube#searchListResponse",
     "etag": "\"oqbvhYxBE6fAbRk6m7aLlHf5s1I/8Pwx4tA-oE0lcjEgrRoqOeaeu4w\"",
     "nextPageToken": "CAUQAA",
     "pageInfo": {
      "totalResults": 484531,
      "resultsPerPage": 5
     },
     "items": [
      {
       "kind": "youtube#searchResult",
       "etag": "\"oqbvhYxBE6fAbRk6m7aLlHf5s1I/RzPtjac7Nh1ggOliIdOlMbB_qls\"",
       "id": {
        "kind": "youtube#video",
        "videoId": "PywWIHqiwD0"
       },
       "snippet": {
        "publishedAt": "2011-11-18T15:57:15.000Z",
        "channelId": "UCekTpzKodObpOcmvVCFUvTw",
        "title": "Turkana woman breastfeeds orphaned goat",
        "description": "http://www.ntv.co.ke A woman in Turkana has been taking care of an orphaned she goat for five months in an unorthodox manner. The woman rescued the kid ...",
        "thumbnails": {
         "default": {
          "url": "https://i.ytimg.com/vi/PywWIHqiwD0/default.jpg"
         },
         "medium": {
          "url": "https://i.ytimg.com/vi/PywWIHqiwD0/mqdefault.jpg"
         },
         "high": {
          "url": "https://i.ytimg.com/vi/PywWIHqiwD0/hqdefault.jpg"
         }
        },
        "channelTitle": "NTVKenya",
        "liveBroadcastContent": "none"
       }
      },
      {
       "kind": "youtube#searchResult",
       "etag": "\"oqbvhYxBE6fAbRk6m7aLlHf5s1I/boF8bbeOYRKjwV6Y_dmUEwIMD9Y\"",
       "id": {
        "kind": "youtube#video",
        "videoId": "mmLD5ztBEp4"
       },
       "snippet": {
        "publishedAt": "2014-06-06T22:38:02.000Z",
        "channelId": "UCekTpzKodObpOcmvVCFUvTw",
        "title": "#theTrend: Socialite Vera Sidika's new look",
        "description": "Vera Sidika tells Larry Madowo about her skin lightening procedure, what she does for a living and her expensive lifestyle For more news visit ...",
        "thumbnails": {
         "default": {
          "url": "https://i.ytimg.com/vi/mmLD5ztBEp4/default.jpg"
         },
         "medium": {
          "url": "https://i.ytimg.com/vi/mmLD5ztBEp4/mqdefault.jpg"
         },
         "high": {
          "url": "https://i.ytimg.com/vi/mmLD5ztBEp4/hqdefault.jpg"
         }
        },
        "channelTitle": "NTVKenya",
        "liveBroadcastContent": "none"
       }
      },
      {
       "kind": "youtube#searchResult",
       "etag": "\"oqbvhYxBE6fAbRk6m7aLlHf5s1I/Bt6PHnNvhHX1COI1T3SPm9DVwUE\"",
       "id": {
        "kind": "youtube#video",
        "videoId": "fQOmP8bNjqw"
       },
       "snippet": {
        "publishedAt": "2013-04-27T19:23:09.000Z",
        "channelId": "UCekTpzKodObpOcmvVCFUvTw",
        "title": "Kenyan Spirit: Kenyan athlete gave up winning to help colleague",
        "description": "http://www.ntv.co.ke And now to a story about selflessness and sacrifice and its about a Kenyan athlete. A picture they say is worth a thousand words and when a ...",
        "thumbnails": {
         "default": {
          "url": "https://i.ytimg.com/vi/fQOmP8bNjqw/default.jpg"
         },
         "medium": {
          "url": "https://i.ytimg.com/vi/fQOmP8bNjqw/mqdefault.jpg"
         },
         "high": {
          "url": "https://i.ytimg.com/vi/fQOmP8bNjqw/hqdefault.jpg"
         }
        },
        "channelTitle": "NTVKenya",
        "liveBroadcastContent": "none"
       }
      },
      {
       "kind": "youtube#searchResult",
       "etag": "\"oqbvhYxBE6fAbRk6m7aLlHf5s1I/ReuOIGBmLl_r53O88M9HMNlEwI4\"",
       "id": {
        "kind": "youtube#video",
        "videoId": "LeyBaXQPe1E"
       },
       "snippet": {
        "publishedAt": "2013-11-03T20:39:58.000Z",
        "channelId": "UCekTpzKodObpOcmvVCFUvTw",
        "title": "NTV Investigates: Seeds of Sin",
        "description": "Religion has and will always be an emotive subject to many Kenyans. The constitution guarantees freedom of worship, but some are taking advantage of the ...",
        "thumbnails": {
         "default": {
          "url": "https://i.ytimg.com/vi/LeyBaXQPe1E/default.jpg"
         },
         "medium": {
          "url": "https://i.ytimg.com/vi/LeyBaXQPe1E/mqdefault.jpg"
         },
         "high": {
          "url": "https://i.ytimg.com/vi/LeyBaXQPe1E/hqdefault.jpg"
         }
        },
        "channelTitle": "NTVKenya",
        "liveBroadcastContent": "none"
       }
      },
      {
       "kind": "youtube#searchResult",
       "etag": "\"oqbvhYxBE6fAbRk6m7aLlHf5s1I/E5tUCJn1PIsHvXyaUiRT9-ENiI8\"",
       "id": {
        "kind": "youtube#video",
        "videoId": "zMtzSqLgkP8"
       },
       "snippet": {
        "publishedAt": "2012-04-23T19:15:19.000Z",
        "channelId": "UCekTpzKodObpOcmvVCFUvTw",
        "title": "Naked injustice:Ugandan women protest activist's arrest",
        "description": "http://www.ntv.co.ke Hundreds of women activists in Uganda stripped to protest the arrest of a fellow activist. The women accused the police of mishandling the ...",
        "thumbnails": {
         "default": {
          "url": "https://i.ytimg.com/vi/zMtzSqLgkP8/default.jpg"
         },
         "medium": {
          "url": "https://i.ytimg.com/vi/zMtzSqLgkP8/mqdefault.jpg"
         },
         "high": {
          "url": "https://i.ytimg.com/vi/zMtzSqLgkP8/hqdefault.jpg"
         }
        },
        "channelTitle": "NTVKenya",
        "liveBroadcastContent": "none"
       }
      }
     ]
    }