2

我正在尝试使用 Android 中的 YouTube API v3 获取我的 YouTube 帐户下的所有频道详细信息。这是相同的代码。

YouTube youtube = new YouTube.Builder(transport, jsonFactory,
                        credential).setApplicationName(Constants.APP_NAME)
                        .build();
ChannelListResponse clr = youtube.channels()
                            .list("contentDetails").setMine(true).execute();

Log.d("","Channel count = "+clr.getItems().size());

目前,我在我的帐户下配置了 2 个频道。但是上面的行总是将通道数打印为 1。

关于如何使用 API 获取所有频道详细信息的任何想法?

提前致谢。

4

1 回答 1

2

试试这个代码,它来自https://developers.google.com/youtube/v3/code_samples/java

// Construct a request to retrieve the current user's channel ID.
        // See https://developers.google.com/youtube/v3/docs/channels/list
        YouTube.Channels.List channelRequest = youtube.channels().list("contentDetails");
        channelRequest.setMine(true);

        // In the API response, only include channel information needed
        // for this use case.
        channelRequest.setFields("items/contentDetails");
        ChannelListResponse channelResult = channelRequest.execute();

        List<Channel> channelsList = channelResult.getItems();
        if (channelsList != null) {
            // The user's default channel is the first item in the list.
            String channelId = channelsList.get(0).getId();

            //USE FOR LOOP HERE TO RETRIEVE ALL CHANNELS 
        }

谢谢。这可能会对您有所帮助。

于 2014-07-18T12:38:21.390 回答