2016-07-06 57 views
-3

我想在我的PHP页面中显示youtube结果。 我已经使用函数simplexml_load_file()应该返回一个XML对象。错误使用simplexml_load_file()php

$link = "http://gdata.youtube.com/feeds/api/users/aliensabductedme/favorites"; 
$xml = simplexml_load_file($link); 

我得到一个HTTP请求错误。 我已经知道gdata.youtube.com现在不起作用。 so ..有什么替代它,这样我可以使用simplexml_load_file() PHP函数。

+2

如果该链接不再起作用,那么这与php的功能无关。 – Devon

回答

0

Youtube更改了它的xml提要的网址...您可以通过查看播放列表中的源代码来查找您想要获取网址的新网址。就在源代码中搜索“PLAYLIST_ID”,并找到正确的ID,然后使用该ID在下面的格式为$链接

$link = "https://www.youtube.com/feeds/videos.xml?playlist_id=FLL8mk53VPSk5tKXixJq-FTA"; 
$xml = simplexml_load_file($link); 
+0

虽然代码经常为自己说话,但只包含代码且没有文本解释的答案会被标记为复审队列。您可以通过添加一个或两个解释来避免这种情况。 – Will

+0

@Will ....很高兴知道...我是新来的。 – Jeremy

0

不知道这仍然是需要的,但我迁移我的代码api-v2到api-v3,我不再使用simplexml

因为它是现在需要用户,密钥和易于使用的,我已经切换到json_decode

例如:

$url_link = 'https://www.googleapis.com/youtube/v3/videos?part=snippet&id=[VIDEO_ID]&key=[API_KEY]'; 

$video = file_get_contents($url_link); 
$data= json_decode($video, true); 

$vid = $data['id']; 

..........等。

我有点喜欢它更好。 (^ - ^)