小编jos*_*svm的帖子

如何使用Android中的youtube数据API搜索视频

我正在Android中开发一个应用程序,需要通过关键字搜索YouTube的视频.我使用了Youtube数据API,代码如下:

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

        // 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
        search.setKey(DeveloperKey.DEVELOPER_KEY);
        search.setQ("dogs");

        // Restrict the search results to only include videos. See:
        // https://developers.google.com/youtube/v3/docs/search/list#type
        search.setType("video");

        // 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(25); …
Run Code Online (Sandbox Code Playgroud)

youtube android youtube-api android-youtube-api

8
推荐指数
2
解决办法
2万
查看次数