【问题标题】:Get channels using YouTube API使用 YouTube API 获取频道
【发布时间】:2014-09-09 13:41:53
【问题描述】:

我正在尝试使用 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 获取所有频道详细信息吗?

提前致谢。

【问题讨论】:

标签: java android youtube-api youtube-channels


【解决方案1】:

试试这个来自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 
        }

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

【讨论】:

  • 我面临同样的问题,我创建了 2 个频道,但我只得到一个
猜你喜欢
  • 1970-01-01
  • 2014-03-14
  • 2017-07-25
  • 2015-07-16
  • 2018-10-19
  • 2020-12-07
  • 2023-03-31
  • 2018-10-28
  • 1970-01-01
相关资源
最近更新 更多