开发者

How to fetch youtube video data using php?

开发者 https://www.devze.com 2023-04-12 02:48 出处:网络
I need to get the XML data from youtube for a particular video(based on ID) and fetch the thumbnail url. I am using PHP.

I need to get the XML data from youtube for a particular video(based on ID) and fetch the thumbnail url. I am using PHP. The code is as follows:

<?php

//$xmlFilePath = 'http://localhost/testFile.xml'; //This works..
$xmlFilePath = 'https://gdata.youtube.com/feeds/api/videos/5P6UU6m3cqk?v=2';

$dataFromYoutube = file_get_contents($xmlFilePath);
print_r($dataFromYoutube);
?>

I dont get any data. The output is blank. If I load开发者_开发百科 the url 'https://gdata.youtube.com/feeds/api/videos/5P6UU6m3cqk?v=2' in browser and copy the content to a file(http://localhost/testFile.xml), then the above code works. I have tried fetching the youtube data using ajax and also simlexml_load_file function in php. But the result is blank/empty for Youtube url. However, I get the data for 'http://localhost/testFile.xml' in both cases. How can I fetch youtube data using php?

Please help.


well, your code is correct and works fine too. It may be that your apache server is not configured for "https". So just check it once too.

0

精彩评论

暂无评论...
验证码 换一张
取 消