2016-07-06 74 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']; 

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

我有點喜歡它更好。 (^ - ^)