【问题标题】:Vimeo oEmbed not working with curl+PHPVimeo oEmbed 不适用于 curl+PHP
【发布时间】:2015-11-12 23:00:29
【问题描述】:

我正在尝试使用 oEmbed 来测试是否存在 Youtube 或 Vimeo 视频。我的代码适用于 Youtube,但不适用于 Vimeo,即使我关注 Vimeo's official documentation for oEmbed 和那里提供的示例。为什么我的代码不适用于 Vimeo?我得到 Youtube 的服务器响应 200,但 Vimeo 的服务器响应 0。我的代码是:

<?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>

【问题讨论】:

  • 我将您的脚本复制/粘贴到我的服务器上并收到了Server response: 200。也许是暂时的打嗝?
  • 其实你是对的。我已经从 localhost 运行了这个脚本,它适用于 Youtube,但不适用于 Vimeo。我将此文件上传到服务器,它工作正常。下次我绝对应该更加小心,并在真实服务器而不是本地主机中测试与外部站点的连接。

标签: vimeo vimeo-api oembed


【解决方案1】:

问题来自使用 localhost 连接到 Vimeo。 Localhost 可以在 Youtube 上正常工作,但不能在 Vimeo 上工作。根据另一位成员的建议,我已经在真实服务器中测试了上述脚本,并且一切正常。

历史道德:始终在真实服务器中测试有问题的外部连接,而不是在本地主机上。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-21
    • 2011-09-09
    • 2016-11-25
    • 2016-10-19
    • 2014-01-22
    • 2017-07-27
    • 2017-06-16
    相关资源
    最近更新 更多