位DailyMotion API请求返回空白结果 [英] Dailymotion API request returning blank result

查看:367
本文介绍了位DailyMotion API请求返回空白结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的code检索视频ID,标题,缩略图,持续时间和标签。

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);

然而,它返回空/空白页。我使用在我的本地这可能是什么问题?我可以调用的https://api.dailymotion.com/video/xreczc?fields=title,duration,thumbnail_url,id,tags直接在浏览器和它的作品。

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.

任何帮助或想法?

推荐答案

这code似乎解决它。

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;
}

这篇关于位DailyMotion API请求返回空白结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆