Question

I am using the youtube data api v3, but I ma having a weird issue. I do understand that for pagination, I need to use the nextPageTokem from the response while sending the subsequent request, but my issue is that, I am not getting a nextPageToken in the response. My code is as below.

      youtube = new YouTube.Builder(HTTP_TRANSPORT, JSON_FACTORY, new HttpRequestInitializer() {
    public void initialize(HttpRequest request) throws IOException {}
  }).setApplicationName("DMT").build();


  String queryTerm = "<my movie>";

  YouTube.Search.List search = youtube.search().list("id,snippet");


  String apiKey = properties.getProperty("youtube.apikey");
  search.setQ(queryTerm);
  search.setVideoDuration("long");

  search.setType("video");
  search.setFields("items(*)");
  SearchListResponse searchResponse = search.execute();
      System.out.println(searchResponse.toPrettyString());
      System.out.println(searchResponse.getNextPageToken());

  List<SearchResult> searchResultList = searchResponse.getItems();


  if (searchResultList != null) {
      System.out.println(searchResponse.getPageInfo());
      prettyPrint(searchResultList.iterator(), queryTerm);
  }

What am I missing? Do I need to set some thing to get the header in the response?

Thanks in advance for your answer

Was it helpful?

Solution

It's because you are setting fields to only return "items". If you want to only return items and nextpageToken, you can set it to "items,nextPageToken"

OTHER TIPS

// Recursive function to print an entire feed.
 public static void printEntireVideoFeed(YouTubeService service, 
VideoFeed videoFeed, boolean detailed) throws MalformedURLException, 
IOException, ServiceException {
 do {
     printVideoFeed(videoFeed, detailed);
     if(videoFeed.getNextLink() != null) {
     videoFeed = service.getFeed(new URL(videoFeed.getNextLink().getHref()), 
     VideoFeed.class);
     }
 else {
        videoFeed = null;
       }  
    }
while(videoFeed != null);
 }

// Sample use of recursive function. Print all results for search term "puppy".

YouTubeQuery query = 
new YouTubeQuery(new URL("http://gdata.youtube.com/feeds/api/videos"));
query.setFullTextQuery("puppy");
VideoFeed videoFeed = service.query(query, VideoFeed.class);
printEntireVideoFeed(service, videoFeed, false);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top