使用php youtube api无法在json中获得objet

时间:2015-06-18 09:21:11

标签: php json youtube

我想使用youtube的api V3获取频道的最后一个视频。

当我在php中尝试时,我无法获得“videoId”

<?php
$url = "https://www.googleapis.com/youtube/v3/playlistItems?          part=snippet&maxResults=1&playlistId=XX&key=XX";
 $obj = json_decode($json);
 print $json_output->{'snippet'}->{'ressourceId'}->{'videoId'};
?>

没有打印出来的。

你能帮助我吗? 谢谢

编辑: 网址: https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=1&playlistId=PLcsF2yXOMjK-nfdafvV3pNPY6Va28y5p1&key=AIzaSyBpu8hgnXbkqFVWrAvwRUEz7T13ii3I7WM

1 个答案:

答案 0 :(得分:0)

$json = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=1&playlistId=PLcsF2yXOMjK-nfdafvV3pNPY6Va28y5p1&key=AIzaSyBpu8hgnXbkqFVWrAvwRUEz7T13ii3I7WM";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$json);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        $result=curl_exec($ch);
        curl_close($ch);
        echo "<pre>";
        print_r(json_decode($result,true));
        echo "</pre>";

使用这样来获取数据