我正在尝试使用关键字从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();
}
答案 0 :(得分:5)
由于你没有提到nextpagetoken或pageinfo字段,你得到null, 显式设置字段时,搜索结果集会受到限制。
var data = "data-translate='view-7631b26ea80b1b601c313b15cc4e2ab03faedf30'>Avatar data";
data = data.match(/'\b(.*)\b'/gm)
输出: 输入搜索字词
扑克脸PAGE INFO:{“resultsPerPage”:2,“totalResults”:667891}
下一页令牌:CAIQAA
prev page token:null