php - Youtube Api to get video description with video id -
i trying discriptiobn youtube using api .... dont no wrong not getting single video . if try playlist working fine, not video id
here code
error_reporting(e_all); $feedurl = 'https://gdata.youtube.com/feeds/api/playlists/'.$id.'?v=2&prettyprint=true'; $sxml = simplexml_load_file($feedurl); echo $feedurl.'</br>'; foreach ($sxml->entry $entry) { echo $media->group->description; } above code working playlist ... if try 1 video not working:
error_reporting(e_all); $feedurl = 'http://gdata.youtube.com/feeds/api/videos/'.$id.'?v=2&alt=json&prettyprint=true'; $sxml = simplexml_load_file($feedurl); echo $feedurl.'</br>'; foreach ($sxml->entry $entry) { echo $media->group->description; }
if call youtube api 'alt=json' parameter, response formatted json not xml. should use:
$response = json_decode(file_get_contents('... api url ...'), true); and 'description' can accessed with:
$response['entry']['media$group']['media$description']['$t']
Comments
Post a Comment