DailyMotionAPI PHP问题

DailyMotionAPI PHP问题,php,api,vimeo,Php,Api,Vimeo,以下代码适用于Vimeo API: function getTitle($id){ $title = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$id.php")); $theTitle=$title[0]['title']; echo $theTitle; } 如果我使用Dailymotion: $id2 = 'xks75n'; function dailyMotionTitle

以下代码适用于Vimeo API:

function getTitle($id){
    $title = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$id.php"));
    $theTitle=$title[0]['title'];
    echo $theTitle;
}
如果我使用Dailymotion:

 $id2 = 'xks75n';
    function dailyMotionTitle($id2){
        $dm = unserialize(file_get_contents("http://www.dailymotion.com/embed/video/".$id2));
        echo $dm[0]['title'];
    }

我在1374字节的偏移量0处出错。我知道我可以使用embed.ly或JSON解析,但我更喜欢PHP。任何关于修复Dailymotion PHP解析的帮助,我们都将不胜感激。

您的运气可能会更好

'https://api.dailymotion.com/video/'. $id2 .'?fields=title'

你不能仅仅改变URL,就指望它能起作用

阅读本页,了解如何通过编程方式访问视频信息

例如,使用REST API,要获取JSON格式响应中的视频标题,请获取:

https://api.dailymotion.com/video/xks75n?fields=title
返回

{
    "title": "The Farmer and His Sons- Aesop's fables"
}
{
    "type": "video",
    "version": "1.0",
    "provider_name": "Dailymotion",
    "provider_url": "http:\/\/www.dailymotion.com",
    "title": "The Farmer and His Sons- Aesop's fables",
    "author_name": "hooplakidz",
    "author_url": "http:\/\/www.dailymotion.com\/hooplakidz",
    "width": 480,
    "height": 269,
    "html": "<iframe src=\"http:\/\/www.dailymotion.com\/embed\/video\/xks75n\" width=\"480\" height=\"269\" frameborder=\"0\"></iframe>",
    "thumbnail_url": "http:\/\/static2.dmcdn.net\/static\/video\/369\/709\/34907963:jpeg_preview_large.jpg?20110830044159",
    "thumbnail_width": 426.666669846,
    "thumbnail_height": 240
}

另一个选择是在问题中的URL上使用

http://www.dailymotion.com/services/oembed?format=json&url=http://www.dailymotion.com/embed/video/xks75n
返回

{
    "title": "The Farmer and His Sons- Aesop's fables"
}
{
    "type": "video",
    "version": "1.0",
    "provider_name": "Dailymotion",
    "provider_url": "http:\/\/www.dailymotion.com",
    "title": "The Farmer and His Sons- Aesop's fables",
    "author_name": "hooplakidz",
    "author_url": "http:\/\/www.dailymotion.com\/hooplakidz",
    "width": 480,
    "height": 269,
    "html": "<iframe src=\"http:\/\/www.dailymotion.com\/embed\/video\/xks75n\" width=\"480\" height=\"269\" frameborder=\"0\"></iframe>",
    "thumbnail_url": "http:\/\/static2.dmcdn.net\/static\/video\/369\/709\/34907963:jpeg_preview_large.jpg?20110830044159",
    "thumbnail_width": 426.666669846,
    "thumbnail_height": 240
}
{
“类型”:“视频”,
“版本”:“1.0”,
“提供商名称”:“Dailymotion”,
“提供者url”:“http:\/\/www.dailymotion.com”,
“标题”:“农夫和他的儿子——伊索寓言”,
“作者姓名”:“hooplakidz”,
“作者url”:“http:\/\/www.dailymotion.com\/hooplakidz”,
“宽度”:480,
“高度”:269,
“html”:“,
“缩略图url”:“http:\/\/static2.dmcdn.net\/static\/video\/369\/709\/34907963:jpeg\u preview\u large.jpg?20110830044159”,
“缩略图宽度”:426.666669846,
“缩略图高度”:240
}


提示:您可以使用将其“解码”到PHP对象或数组中以访问值。

如果您使用PHP,简单的方法是使用Dailymotion PHP SDK:

日常运动有很大的影响

试一试


此url返回给定的视频