gpt4 book ai didi

java - Youtube 搜索 :list getting PageInfo and nextPageToken null

转载 作者:行者123 更新时间:2023-11-29 07:38:10 26 4
gpt4 key购买 nike

我正在尝试使用关键字从 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();
}

最佳答案

你得到的是 null 因为你没有提到 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}

下一页 token :CAIQAA

上一页token:null

关于java - Youtube 搜索 :list getting PageInfo and nextPageToken null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33124788/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com