0

動画からコメントを取得していますが、「作成者名」とその ID が NULL になっています。

これは私が持っているものです。

$feedUrl='http://gdata.youtube.com/feeds/api/videos/'.$selected_video_id.'/comments?v=2&alt=json';  
$data = json_decode(file_get_contents($feedUrl),true);
$info = $data["feed"];
$entry = $info["entry"];
$nEntry = count($entry);

for($i=0;$i<$nEntry;$i++){ 
    $name =  $entry[$i]['author']['name']['$t'];
    $userId = $entry[$i]['author']['yt$userId']['$t'];
    $content = $entry[$i]['content']['$t'];
    $published_2 = $entry[$i]['published']['$t'];
}

コンテンツと公開は問題なく収集されますが、名前とユーザー ID は収集されません。

フィードには、YouTube データ API デモ ベータ版で見た要素が含まれています。また、ブラウザでフィード リクエストを実行すると、すべてが表示されます。

http://gdata.youtube.com/feeds/api/videos/VIDEO_ID/comments

それで、私は何かを逃していますか?

4

1 に答える 1

1

そのはず:

$name =  $entry[$i]['author'][0]['name']['$t'];
$userId = $entry[$i]['author'][0]['yt$userId']['$t'];
$content = $entry[$i]['content']['$t'];
$published_2 = $entry[$i]['published']['$t'];

またはさらに良い:

$feedUrl=file_get_contents('http://gdata.youtube.com/feeds/api/videos/ASO_zypdnsQ/comments?v=2&alt=json'); 
$json = json_decode($feedUrl, true);
foreach($json['feed']['entry'] as $entry) {
    echo $entry['author'][0]['name']['$t']."<br>";
    echo $entry['author'][0]['yt$userId']['$t']."<br>";
    echo $entry['content']['$t']."<br>";
    echo $entry['published']['$t']."<br>";
}

上記のように使用できますforeach:)

于 2013-06-27T20:13:42.867 に答える