使用Youtube数据api v3获取所有频道

时间:2016-04-01 06:38:37

标签: java android youtube-api youtube-data-api youtube-channels

我想通过在Android中使用Youtube数据api v3来获取用户的所有频道,我正在使用频道:列表 https://developers.google.com/youtube/v3/docs/channels/list#http-request 得到所有渠道,

public static void getChannelID(YouTube youtube){
        try {
            Log.i(MainActivity.APP_NAME, "Requesting ChannelID.");

             com.google.api.services.youtube.YouTube.Channels.List Channel = youtube.channels().list("id,snippet,contentDetails");
             Channel.setMine(true);

            // In the API response, only include channel information needed
             // for this use case.
             Channel.setFields("items/contentDetails, items/id, items/snippet");
             // List request is executed and list of broadcasts are returned
             ChannelListResponse returnedListResponse = Channel.execute();
            // Since the API request specified a unique channel ID, the API
             // response should return exactly one channel. If the response does
             // not contain a channel, then the specified channel ID was not found.
             List<Channel> channelList = returnedListResponse.getItems();

             Log.e("=========channelList.size=========", ""+channelList.size());

             for (int i = 0; i < channelList.size(); i++) {
                 if (channelList != null) {
                     // The user's default channel is the first item in the list.
                     String channelId = channelList.get(i).getId();
                     Log.e("=========channelId=========", ""+channelId);
                     Log.e("=========getContentDetails=========", ""+channelList.get(i).getContentDetails());
                     Log.e("=========getSnippet=========", ""+channelList.get(i).getSnippet());
                     //Log.i("getStatus", ""+channelList.get(i).getStatus());
                     //Log.i("getKind", ""+channelList.get(i).getKind());
                     //USE FOR LOOP HERE TO RETRIEVE ALL CHANNELS 
                 }
             }

        }catch (GoogleJsonResponseException e) {
            Log.e("GoogleJsonResponseException", e.toString());
            System.err.println("GoogleJsonResponseException code: "
                    + e.getDetails().getCode() + " : "+ e.getDetails().getMessage());
            e.printStackTrace();

        }catch (IOException e) {
            System.err.println("IOException: " + e.getMessage());
            e.printStackTrace();
        }  catch (Throwable t) {
            System.err.println("Throwable: " + t.getMessage());
            t.printStackTrace();
        }
    }

目前,我已在我的帐户下配置了2个频道。但上面的行总是将通道数打印为1。 如何使用API​​获取所有频道详细信息?

0 个答案:

没有答案