0

I am using the following code to retrieve video ID, title, thumbnail, duration and tags.

$dailymotion = "https://api.dailymotion.com/video/xreczc?fields=title,duration,thumbnail_url,id,tags";
$curl = curl_init($dailymotion);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($curl);
curl_close($curl);
$results = json_decode($return, true);
print_r($results);

However it returns empty/blank page. I am using this on my localhost what could be wrong? I can call https://api.dailymotion.com/video/xreczc?fields=title,duration,thumbnail_url,id,tags directly in the browser and it works.

Any help, or ideas?

Ahmed Fouad
  • 2,963
  • 10
  • 30
  • 54

3 Answers3

1

Please try with this one.

$dailymotion = file_get_contents("https://api.dailymotion.com/video/xreczc?fields=title,duration,thumbnail_url,id,tags");

$results = json_decode($dailymotion, true);

print_r($results);
Kijewski
  • 25,517
  • 12
  • 101
  • 143
user9001
  • 11
  • 4
  • You shouldn't disable verifying ssl certificates. Your code does just that. They are there for a reason. – Sven Oct 10 '12 at 21:25
0

You are trying to fetch a https link via curl which has known issues. See the following links to see if they help your issue.

Can't connect to HTTPS site using cURL. Returns 0 length content instead. What can I do?

http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/

Regards,

Community
  • 1
  • 1
web-nomad
  • 6,003
  • 3
  • 34
  • 49
0

This code seems to fix it.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.dailymotion.com/video/".$id."?fields=id,title,thumbnail_url,tags,duration,embed_url");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$results = curl_exec($ch);
curl_close($ch);
$results = json_decode($results);
if (!$results || $results->error->code) {
    return false;
} else {
    return $results;
}
Ahmed Fouad
  • 2,963
  • 10
  • 30
  • 54