【发布时间】:2018-09-22 11:14:29
【问题描述】:
嘿,我有问题需要从一个 json 获取信息到另一个 json 链接。 我需要从下面的链接中获取 all(maxResults) videoId
https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId=UCynfZM0Edr9cA4pDymb2rEA&maxResults=20&key=AIzaSyDVTF2abNVa5pRitb8MVz1ceJFhE-2y_qk
到此区域下方的此链接 [此处需要带有 的 videoId,每个]
https://www.googleapis.com/youtube/v3/videos/?id=[NEED HERE videoId with , each]&part=statistics&key=AIzaSyDVTF2abNVa5pRitb8MVz1ceJFhE-2y_qk
所有代码
<?php
$videoList = json_decode(file_get_contents('https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId=UCynfZM0Edr9cA4pDymb2rEA&maxResults=20&key=AIzaSyDVTF2abNVa5pRitb8MVz1ceJFhE-2y_qk'));
$url = 'https://www.googleapis.com/youtube/v3/videos/?id=[NEED HERE IDS]&part=statistics&key='.$API.'';
$videoViews = json_decode(file_get_contents($url));
foreach($videoList->items as $item){
//Shows embed videos from channels
if(isset($item->id->videoId)){
echo '<div class="video">
<iframe width="280" height="150" src="https://www.youtube.com/embed/'.$item->id->videoId.'" frameborder="0" allowfullscreen></iframe>
<h5>'. $item->snippet->title .'</h5>
</div>';
}
}
?>
我需要看起来像这样 3 videoId 添加但来自第一个 json 信息
https://www.googleapis.com/youtube/v3/videos/?id=w_TLR7K_g98,H5_LI7caH1M,ishpS2v9uvo&part=statistics&key='.$API.'
【问题讨论】:
-
那么,您遇到了什么问题?
-
从第一个链接我得到 videoId,我需要自动添加到第二个 $url 以获取 videoId 统计信息。现在我只得到 videoId,但我不想手动添加它,我需要像 foreach ($videoList->items as $items) { if(isset($items->id->videoId)){ echo ''.$items->id->videoId.','; } } 但在googleapis.com/youtube/v3/videos/?id=[NEED HERE videoId 中,每个]&part=statistics&key=AIzaSyDVTF2abNVa5pRitb8MVz1ceJFhE-2y_qk 对不起英语。
标签: php arrays json api decode