0
我试图使用oEmbed来测试Youtube或Vimeo视频是否存在。我的代码在Youtube上可以正常工作,但它不适用于Vimeo,即使我遵循Vimeo's official documentation for oEmbed和此处提供的示例。为什么我的代码不适用于Vimeo? Youtube获得200的服务器响应,但Vimeo的服务器响应为0。我的代码是:Vimeo oEmbed不能使用卷曲+ PHP
<?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>
我复制/粘贴你的脚本到我的服务器上,并收到'服务器响应:200'。也许这是一个暂时的呃逆? – johnh10
其实你是对的。我已经从localhost运行这个脚本,它适用于Youtube,但不适用于Vimeo。我将这个文件上传到服务器,并且它工作正常。下次我应该更加小心,并在真实服务器中测试与外部站点的连接,而不是在本地主机上。 – Daniel