Получение каналов с помощью YouTube API

Я пытаюсь получить всю информацию о канале в своей учетной записи YouTube с помощью YouTube API v3 в Android. Вот код того же.

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?

Заранее спасибо.


person Kameswari    schedule 18.07.2014    source источник
comment
У меня такая же проблема, я создал 2 канала, но получаю только один   -  person Achin    schedule 01.04.2016


Ответы (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 
        }

Спасибо. Это может вам помочь.

person sais    schedule 18.07.2014
comment
У меня такая же проблема, я создал 2 канала, но получаю только один - person Achin; 01.04.2016