youtube API V3在网页上显示视频的问题(snippet,thumbs,title) [英] youtube API V3 probleme of (snippet, thumbs, title,) displaying videos on web page
本文介绍了youtube API V3在网页上显示视频的问题(snippet,thumbs,title)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的api Key存在问题。当我尝试一个请求:
我得到一个空数组
{
kind:youtube #videoListResponse,
etag:\RmznBCICv9YtgWaaa_nWDIH1_GM / Rk41fm-2TD0VG1yv0-bkUvcBi9s\,
pageInfo:{
totalResults:0,
resultsPerPage:0
},
items:[
]
}
在视频在网站上显示效果良好之前,我的关键似乎很好,但现在我不知道为什么在尝试从YouTube获取数据时没有响应。
我有这个方法:
public function getYoutube($ id )
{
$ youtube ='https://www.googleapis.com/youtube/v3/videos?id ='。$ id。'& fields = items%28snippet%28title,description, %20thumbnails%29%29&安培;部分=片断&安培;键= my_key';
$ json = file_get_contents($ youtube);
$ itemList = json_decode($ json);
$ this-> video = $ itemList-> items [0];
$ this-> id = $ id;
if(!$ json)
return false;
else
return $ this-> video;
解决方案
听起来像 file_get_contents
失败。
- 检查你的php.ini,看看 allow_url_fopen 已禁用。
将来,请检查可能返回失败的函数的结果,例如
$ json = file_get_contents ($ YouTube)的;
if(false === $ json){
//失败。做一点事。
$ b如果失败,你也可以检查你的服务器的错误文件它应该有更多info。
I have a problem of my api Key. when am trying a request:
I get a empty array
{
"kind": "youtube#videoListResponse",
"etag": "\"RmznBCICv9YtgWaaa_nWDIH1_GM/Rk41fm-2TD0VG1yv0-bkUvcBi9s\"",
"pageInfo": {
"totalResults": 0,
"resultsPerPage": 0
},
"items": [
]
}
my key seems to be good, before videos displayed well on website, but now i dont know why there is no response when am trying a request to get data from YouTube.
I have this method :
public function getYoutube($id)
{
$youtube ='https://www.googleapis.com/youtube/v3/videos?id='.$id.'&fields=items%28snippet%28title,description,%20thumbnails%29%29&part=snippet&key=my_key';
$json = file_get_contents($youtube);
$itemList = json_decode($json);
$this->video = $itemList->items[0];
$this->id = $id;
if(!$json)
return false ;
else
return $this->video ;
}
解决方案 It sounds like file_get_contents
is failing.
- Check your php.ini to see if allow_url_fopen is disabled.
In the future, always check results of functions that can return a failure, such as
$json = file_get_contents($youtube);
if ( false === $json ) {
// it failed. do something.
}
If it failed you can also check your server's error file it should have some more info.
这篇关于youtube API V3在网页上显示视频的问题(snippet,thumbs,title)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文