0

我正在尝试通过为它们创建的 oEmbed API 端点为 Vine 提取 JSON 数据。该请求在浏览器和我的本地 Vagrant 机器上运行良好,但是一旦我在服务器上运行它,它就会引发 500 Internal Server Error。就好像我的 Rackspace 服务器已被阻止向其 API 发出请求,但这是我第一次尝试向 Vine 发出请求。

$url = 'https://vine.co/oembed.json?url=http://vine.co/v/egXzgWMjrTj';
$res = file_get_contents($url);
$json = json_decode($res);

我已经尝试使用 cURL 请求并将带有标头的 stream_create_context() 传递到 file_get_contents() 调用中。

我的示例 cURL 请求也返回 HTML 格式的 500 内部服务器错误

$url = 'https://vine.co/oembed.json?url=http://vine.co/v/egXzgWMjrTj';
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);

我的最终目标是获取视频的缩略图,并且我正在向 Vimeo 和 Instagram 执行类似的请求,而不会出现内部服务器错误。

4

1 回答 1

0

这工作,测试它。

$res = file_get_contents('https://vine.co/oembed.json?url=http://vine.co/v/egXzgWMjrTj');
$json = json_decode($res,true);
echo $json['thumbnail_url'];

json_decode 为 true 的第二个参数返回一个数组而不是一个对象。

于 2015-08-14T17:19:06.380 回答