Daniel
Daniel

Reputation: 202

Vimeo oEmbed not working with curl+PHP

I'm trying to use oEmbed to test if a Youtube or Vimeo video exists. My code works fine with Youtube, but it doesn't work with Vimeo, even if I follow Vimeo's official documentation for oEmbed and the example provided there. Why is my code not working for Vimeo? I get a server response 200 for Youtube, but a server response 0 for Vimeo. My code is:

<?php

//Problematic case: I get 0 as a server reponse
$cURL = curl_init("https://vimeo.com/api/oembed.json?url=https%3A//vimeo.com/76979871");

// Youtube case - works fine: server response = 200
// $cURL = curl_init("http://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=ebXbLfLACGM");

// Set option 1: return the result as a string
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);

// Set option 2: Follow any redirect
curl_setopt($cURL, CURLOPT_FOLLOWLOCATION, true);

// Execute the query
$cURLresult = curl_exec($cURL);

// Get the HTTP response code
$response = curl_getinfo($cURL, CURLINFO_HTTP_CODE);

?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Server response</title>
</head>
<body>

<h1><?php print "Server response: " . $response; ?></h1>


</body>
</html>

Upvotes: 0

Views: 830

Answers (1)

Daniel
Daniel

Reputation: 202

The problem came from using localhost to connect to Vimeo. Localhost works fine with Youtube, but not with Vimeo. I've test the above script in a real server, as suggested by another member, and there everything works fine.

Moral of the history: always test problematic external connections in a real server, not on localhost.

Upvotes: 1

Related Questions