如何在php中读取youtube数据api v3响应



我有以下代码:

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

返回以下输出:

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
    (
    )

)

我想循环使用modelData:protected变量来获得通道及其项数据的列表。其json对象so$yt_profiles->modelData:protected在访问时不工作。请帮我解决这个问题。提前感谢

您可以在数组中访问它:

print_r ($yt_profiles['modelData']);

您的请求:

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

访问值频道标题,例如:

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

访问bannerImageUrl的值,例如:

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

这对您有帮助吗?

    $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;
      }
    }

相关内容

  • 没有找到相关文章

最新更新