Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List 如何使用Java通过youtube API v3获取视频的URL_List_Url_Search_Video_Youtube - Fatal编程技术网

List 如何使用Java通过youtube API v3获取视频的URL

List 如何使用Java通过youtube API v3获取视频的URL,list,url,search,video,youtube,List,Url,Search,Video,Youtube,我正在使用Youtube API v3按关键字搜索视频。我目前正在使用以下代码: YouTube youtube; youtube = new YouTube.Builder(GoogleNetHttpTransport.newTrustedTransport(), new JacksonFactory(), new HttpRequestInitializer() { public void initialize(HttpRequest request) throws IOExcept

我正在使用Youtube API v3按关键字搜索视频。我目前正在使用以下代码:

    YouTube youtube;
youtube = new YouTube.Builder(GoogleNetHttpTransport.newTrustedTransport(), new JacksonFactory(), new HttpRequestInitializer() {
public void initialize(HttpRequest request) throws IOException {
}}).setApplicationName("youtube-cmdline-search-sample").build();
// query term.
String keyword = request.getParameter("keyword");

// api key
String apiKey = "my-api-key";

// Define the API request for retrieving search results.
 YouTube.Search.List search = youtube.search().list("id,snippet");

// Set your developer key from the Google Cloud Console for
// non-authenticated requests. See:
// https://cloud.google.com/console
lstVideos.setKey(apiKey);
search.setKey(apiKey);
search.setQ(keyword);

// To increase efficiency, only retrieve the fields that the
// application uses.
search.setFields("items(id/kind,id/videoId,snippet/title,snippet/thumbnails/default/url)");
search.setMaxResults((long)10);
// Call the API and print results.
SearchListResponse searchResponse = search.execute();
List<SearchResult> searchResultList = searchResponse.getItems();
Iterator<SearchResult> itsearch = searchResultList.iterator();
YouTube;
youtube=new youtube.Builder(GoogleNetHttpTransport.newTrustedTransport()、new JacksonFactory()、new HttpRequestInitializer()){
公共无效初始化(HttpRequest请求)引发IOException{
}}).setApplicationName(“youtube cmdline搜索示例”).build();
//查询条件。
字符串关键字=request.getParameter(“关键字”);
//api密钥
String apiKey=“我的api密钥”;
//定义检索搜索结果的API请求。
YouTube.Search.List Search=YouTube.Search().List(“id,snippet”);
//从Google云控制台设置开发者密钥
//未经身份验证的请求。见:
// https://cloud.google.com/console
lstVideos.setKey(apiKey);
search.setKey(apiKey);
search.setQ(关键字);
//为了提高效率,只检索
//应用程序使用。
search.setFields(“项(id/kind、id/videoId、片段/标题、片段/缩略图/默认值/url)”;
search.setMaxResults((长)10);
//调用API并打印结果。
SearchListResponse searchResponse=search.execute();
List searchResultList=searchResponse.getItems();
迭代器itsearch=searchResultList.Iterator();
这对我来说很好,可以获得一些数据,比如(id、缩略图等)。此代码在上提供

我在stackoverflow()上看到了一个基本相同的问题,但是。。我不知道如何获取这些数据。我看不到任何Java示例,我非常迷茫

有什么帮助吗


谢谢

我知道这是一个老话题,但对于从谷歌登陆的其他人来说,这里有一个答案

SearchResult singleVideo = iteratorSearchResults.next();
ResourceId rId = singleVideo.getId();
只要将rId.getVideoId()放到youtube.com/watch?v=上,您就有了url

String url = "youtube.com/watch?v=" + rId.getVideoId();

@没有显示名称:谢谢您的编辑。在平板电脑上很难使用代码功能。:)@马克:-它发生了:-)