在这种方法之后,我得到了这种格式的对象波纹管。谁能帮我如何从这个对象中读取标题和频道 ID?
$subscriptionResponse = $youtube->subscriptions->listSubscriptions('snippet',
array('channelId' => 'MY_CHANEL_ID', 'maxResults' => '50'));
echo "<pre>";
print_r($subscriptionResponse['items']);
echo "</pre>";
die();
Array
(
[0] => Google_Service_YouTube_Subscription Object
(
[contentDetailsType:protected] => Google_Service_YouTube_SubscriptionContentDetails
[contentDetailsDataType:protected] =>
[etag] => "xxxxxxxxxxxxxxxxx"
[id] => xxxxxxxxxxxxxxxxx
[kind] => youtube#subscription
[snippetType:protected] => Google_Service_YouTube_SubscriptionSnippet
[snippetDataType:protected] =>
[subscriberSnippetType:protected] => Google_Service_YouTube_SubscriptionSubscriberSnippet
[subscriberSnippetDataType:protected] =>
[data:protected] => Array
(
[snippet] => Array
(
[publishedAt] => 2014-03-04T13:51:59.000Z
[title] => THIS IS THE CHANNEL TITLE THAT I WANT TO GET
[description] => xxxxxxxxxxxxxxxx
[resourceId] => Array
(
[kind] => youtube#channel
[channelId] => xxxxxxxxxxxxxxxxx
)
[channelId] => xxxxxxxxxxxxxxxxx
[thumbnails] => Array
(
[default] => Array
(
[url] => https://yt3.ggpht.com/-b1X29Q2BT6A/AAAAAAAAAAI/AAAAAAAAAAA/QdK_MNBrNRU/s88-c-k-no/photo.jpg
)
[high] => Array
(
[url] => https://yt3.ggpht.com/-b1X29Q2BT6A/AAAAAAAAAAI/AAAAAAAAAAA/QdK_MNBrNRU/s240-c-k-no/photo.jpg
)
)
)
)
[processed:protected] => Array
(
)
)
[1] => Google_Service_YouTube_Subscription Object
(
[contentDetailsType:protected] => Google_Service_YouTube_SubscriptionContentDetails
[contentDetailsDataType:protected] =>
[etag] => "xxxxxxxxxxxxxxxxx"
[id] => xxxxxxxxxxxxxxxxx
[kind] => youtube#subscription
[snippetType:protected] => Google_Service_YouTube_SubscriptionSnippet
[snippetDataType:protected] =>
[subscriberSnippetType:protected] => Google_Service_YouTube_SubscriptionSubscriberSnippet
[subscriberSnippetDataType:protected] =>
[data:protected] => Array
(
[snippet] => Array
(
[publishedAt] => 2014-03-04T13:50:42.000Z
[title] => THIS IS THE CHANNEL TITLE THAT I WANT TO GET
[description] =>
[resourceId] => Array
(
[kind] => youtube#channel
[channelId] => xxxxxxxxxxxxxxxxx
)
[channelId] => xxxxxxxxxxxxxxxxx
[thumbnails] => Array
(
[default] => Array
(
[url] => https://yt3.ggpht.com/-PYEumYpZ18E/AAAAAAAAAAI/AAAAAAAAAAA/LIZhzGw24w4/s88-c-k-no/photo.jpg
)
[high] => Array
(
[url] => https://yt3.ggpht.com/-PYEumYpZ18E/AAAAAAAAAAI/AAAAAAAAAAA/LIZhzGw24w4/s240-c-k-no/photo.jpg
)
)
)
)
[processed:protected] => Array
(
)
)
这行得通吗?
foreach ($subscriptionResponse['items'] as $item) {
echo $item['data']['snippet']['title'];
echo $item['data']['snippet']['channelId'];
}