0
votes

I followed this tut with https://packagist.org/packages/alaouy/youtube

and got it alright but I have a problem in this snippet:

$video = Youtube::getVideoInfo('rie-hPVJ7Sw');
var_dump($video);

This is the response I get:

object(stdClass)#712 (8) { ["kind"]=> string(13) "youtube#video" ["etag"]=> string(57) ""iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/XCpzrqbmTpMEPyMBSGQ0oz6NLe4"" ["id"]=> string(11) "rie-hPVJ7Sw" ["snippet"]=> object(stdClass)#713 (10) { ["publishedAt"]=> string(24) "2013-03-21T02:28:12.000Z" ["channelId"]=> string(24) "UC5ENZAI7prEaHGW1hPgOQEQ" ["title"]=> string(48) "Sergey Brin talks about Google Glass at TED 2013" ["description"]=> string(479) "UPDATE: To address comments about Sergey's poor delivery, I want to emphasize that this is NOT a "TED Talk", despite it being recorded during TED conference. It is pretty much a spontaneous appearance to show the latest technology and wasn't prepared or rehearsed. Google Glass is also not available for purchase yet so it is not strictly speaking a product promotion either. This video is posted mostly because it has details about Glass that were unknown or unconfirmed before." ["thumbnails"]=> object(stdClass)#714 (3) { ["default"]=> object(stdClass)#715 (3) { ["url"]=> string(46) "https://i.ytimg.com/vi/rie-hPVJ7Sw/default.jpg" ["width"]=> int(120) ["height"]=> int(90) } ["medium"]=> object(stdClass)#716 (3) { ["url"]=> string(48) "https://i.ytimg.com/vi/rie-hPVJ7Sw/mqdefault.jpg" ["width"]=> int(320) ["height"]=> int(180) } ["high"]=> object(stdClass)#717 (3) { ["url"]=> string(48) "https://i.ytimg.com/vi/rie-hPVJ7Sw/hqdefault.jpg" ["width"]=> int(480) ["height"]=> int(360) } } ["channelTitle"]=> string(8) "tedleaks" ["tags"]=> array(4) { [0]=> string(11) "sergey brin" [1]=> string(6) "google" [2]=> string(12) "google glass" [3]=> string(3) "ted" } ["categoryId"]=> string(2) "28" ["liveBroadcastContent"]=> string(4) "none" ["localized"]=> object(stdClass)#718 (2) { ["title"]=> string(48) "Sergey Brin talks about Google Glass at TED 2013" ["description"]=> string(479) "UPDATE: To address comments about Sergey's poor delivery, I want to emphasize that this is NOT a "TED Talk", despite it being recorded during TED conference. It is pretty much a spontaneous appearance to show the latest technology and wasn't prepared or rehearsed. Google Glass is also not available for purchase yet so it is not strictly speaking a product promotion either. This video is posted mostly because it has details about Glass that were unknown or unconfirmed before." } } ["contentDetails"]=> object(stdClass)#719 (5) { ["duration"]=> string(8) "PT13M30S" ["dimension"]=> string(2) "2d" ["definition"]=> string(2) "sd" ["caption"]=> string(5) "false" ["licensedContent"]=> bool(false) } ["status"]=> object(stdClass)#720 (5) { ["uploadStatus"]=> string(9) "processed" ["privacyStatus"]=> string(6) "public" ["license"]=> string(7) "youtube" ["embeddable"]=> bool(true) ["publicStatsViewable"]=> bool(true) } ["statistics"]=> object(stdClass)#721 (5) { ["viewCount"]=> string(6) "539812" ["likeCount"]=> string(4) "2450" ["dislikeCount"]=> string(3) "371" ["favoriteCount"]=> string(1) "0" ["commentCount"]=> string(4) "2247" } ["player"]=> object(stdClass)#722 (1) { ["embedHtml"]=> string(116) "

Sorry about the long output line.

What I am after is the video duration time, the thumbnail and the title of the video.

I guess it should be in some form like this.

<?php
  foreach($item as $video)
   {
    echo $item['snippet']['thumbnails]['default'];
   }
?>

Something like that keeps throwing errors.

1

1 Answers

0
votes

It's an stdClass, not array. The correct way to get the info would be

<?php
    $video = Youtube::getVideoInfo('rie-hPVJ7Sw');
    echo $video->snippet->thumbnails->default->url;
?>