3

I have following code:

$yt_profiles = $youtube->channels->listChannels('brandingSettings', array(
'mine' => 'true',
));

That returns the following output:

Google_Service_YouTube_ChannelListResponse Object
(
[collection_key:protected] => items
[etag] => "WFPuK6TsnblcGPcnMex79s42ynQ/sTnuE1bHO-tokx_mFFDt1ybN90g"
[eventId] => 
[itemsType:protected] => Google_Service_YouTube_Channel
[itemsDataType:protected] => array
[kind] => youtube#channelListResponse
[nextPageToken] => 
[pageInfoType:protected] => Google_Service_YouTube_PageInfo
[pageInfoDataType:protected] => 
[prevPageToken] => 
[tokenPaginationType:protected] => Google_Service_YouTube_TokenPagination
[tokenPaginationDataType:protected] => 
[visitorId] => 
[modelData:protected] => Array
    (
        [pageInfo] => Array
            (
                [totalResults] => 1
                [resultsPerPage] => 1
            )

        [items] => Array
            (
                [0] => Array
                    (
                        [kind] => youtube#channel
                        [etag] => "WFPuK6TsnblcGPcnMex79s42ynQ/ecOcHFmWyWQ7ToCD7-B1L36b4L4"
                        [id] => UCQO6uXy5maTpYvSa_yM--Bw
                        [brandingSettings] => Array
                            (
                                [channel] => Array
                                    (
                                        [title] => Vasim Padhiyar
                                        [showRelatedChannels] => 1
                                        [featuredChannelsTitle] => Featured Channels
                                        [featuredChannelsUrls] => Array
                                            (
                                                [0] => UCw-TnDmYDQyjnZ5qpVWUsSA
                                            )

                                        [profileColor] => #000000
                                    )

                                [image] => Array
                                    (
                                        [bannerImageUrl] => http://s.ytimg.com/yts/img/channels/c4/default_banner-vfl7DRgTn.png
                                    )

                                [hints] => Array
                                    (
                                        [0] => Array
                                            (
                                                [property] => channel.featured_tab.template.string
                                                [value] => Everything
                                            )

                                        [1] => Array
                                            (
                                                [property] => channel.banner.image_height.int
                                                [value] => 0
                                            )

                                        [2] => Array
                                            (
                                                [property] => channel.modules.show_comments.bool
                                                [value] => True
                                            )

                                    )

                            )

                    )

            )

    )

[processed:protected] => Array
    (
    )

)

I want to loop through modelData:protected variable to get the list of channels and its items data. Its json object so $yt_profiles->modelData:protected not working while accessing. Please help me to solve this issue. Thanks in advance

3 Answers 3

3

You can reach it as in an array:

print_r ($yt_profiles['modelData']);
Sign up to request clarification or add additional context in comments.

Comments

0

Your request:

$yt_profiles = $youtube->channels->listChannels('brandingSettings', array(
'mine' => 'true',
));

To acces to values Channel title for example:

$titleChannel = $yt_profiles["items"][0]["brandingSettings"]["channel"]["title"];

To acces to values bannerImageUrl for example:

$banner = $yt_profiles["items"][0]["brandingSettings"]["image"]["bannerImageUrl"];

1 Comment

My question was to create loop. Your code isn't dynamic. What if i have more than 1 channel ? I want to replace [0] with dynamic loop variable $i. example: for($i=0; $i<total_channels; $i++)
0

Does this help you?

    $yt_profiles = $youtube->channels->listChannels('id, brandingSettings', array('mine' => 'true',));

    foreach ($yt_profiles['modelData']['items'] as $searchResult) {
      switch ($searchResult['kind']) {
        case 'youtube#channel':
          $channels[]= array('id'=> $searchResult['id'],
                             'brandingSettings'=> $searchResult['brandingSettings']);
          break;
      }
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.