Youtube Search:list 获取 PageInfo 和 nextPageToken 为空
Youtube Search:list getting PageInfo and nextPageToken null
我正在尝试使用关键字从 YouTube 获取视频。我正在使用 YouTube API Java 库。
我可以成功获取前 50 条记录,但要获取下一条记录,需要设置 nextPageToken。但是我得到了 nextPageToken null
。下面是我的代码。
YouTube.Search.List search = youtube.search().list("id,snippet");
search.setOauthToken(credential.getAccessToken());
search.setMaxResults(50L);
search.setQ(keywords); // keywords is string type and input by user.
search.setType("video");
search.setFields("items(id/kind,id/videoId,snippet/title,snippet/thumbnails/default/url)");
VideoList returnList = new VideoList();
do {
search.setKey("MYKEY");
SearchListResponse searchResponse = search.execute();
// This get 50 items proper.
List<SearchResult> searchResultList = searchResponse.getItems();
// Why PageInfo is null?
PageInfo pageInfo = searchResponse.getPageInfo();
// int totalResults = pageInfo.getTotalResults();
// int pageSize = pageInfo.getResultsPerPage();
if(searchResponse != null){
// i use searchResultList and update my database for search.
....
....
// PageToken also null.
String pageToken = searchResponse.getNextPageToken();
search.setPageToken(pageToken);
}
else{
break;
}
} while (true);
}catch(Exception ex){
ex.printStackTrace();
}
你得到的是空值,因为你没有提到 nextpagetoken 或 pageinfo 字段,
当您明确设置字段时,搜索结果集是有限的。
search.setFields("items(kind,id/kind,id/videoId,snippet/title,snippet/thumbnails/default/url),nextPageToken,pageInfo,prevPageToken");
System.out.println("PAGE INFO: " +response.getPageInfo());
System.out.println("next page token :" +response.getNextPageToken());
System.out.println("prev page token:"+ response.getPrevPageToken());
输出:
输入搜索词
扑克脸
页面信息:{"resultsPerPage":2,"totalResults":667891}
下一页令牌:CAIQAA
上一页 token:null
我正在尝试使用关键字从 YouTube 获取视频。我正在使用 YouTube API Java 库。
我可以成功获取前 50 条记录,但要获取下一条记录,需要设置 nextPageToken。但是我得到了 nextPageToken null
。下面是我的代码。
YouTube.Search.List search = youtube.search().list("id,snippet");
search.setOauthToken(credential.getAccessToken());
search.setMaxResults(50L);
search.setQ(keywords); // keywords is string type and input by user.
search.setType("video");
search.setFields("items(id/kind,id/videoId,snippet/title,snippet/thumbnails/default/url)");
VideoList returnList = new VideoList();
do {
search.setKey("MYKEY");
SearchListResponse searchResponse = search.execute();
// This get 50 items proper.
List<SearchResult> searchResultList = searchResponse.getItems();
// Why PageInfo is null?
PageInfo pageInfo = searchResponse.getPageInfo();
// int totalResults = pageInfo.getTotalResults();
// int pageSize = pageInfo.getResultsPerPage();
if(searchResponse != null){
// i use searchResultList and update my database for search.
....
....
// PageToken also null.
String pageToken = searchResponse.getNextPageToken();
search.setPageToken(pageToken);
}
else{
break;
}
} while (true);
}catch(Exception ex){
ex.printStackTrace();
}
你得到的是空值,因为你没有提到 nextpagetoken 或 pageinfo 字段, 当您明确设置字段时,搜索结果集是有限的。
search.setFields("items(kind,id/kind,id/videoId,snippet/title,snippet/thumbnails/default/url),nextPageToken,pageInfo,prevPageToken");
System.out.println("PAGE INFO: " +response.getPageInfo());
System.out.println("next page token :" +response.getNextPageToken());
System.out.println("prev page token:"+ response.getPrevPageToken());
输出: 输入搜索词
扑克脸
页面信息:{"resultsPerPage":2,"totalResults":667891}
下一页令牌:CAIQAA
上一页 token:null