以下代码适用于Vimeo API:
function getTitle($id){
$title = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$id.php"));
$theTitle=$title[0]['title'];
echo $theTitle;
}
Run Code Online (Sandbox Code Playgroud)
如果对于Dailymotion,我使用:
$id2 = 'xks75n';
function dailyMotionTitle($id2){
$dm = unserialize(file_get_contents("http://www.dailymotion.com/embed/video/".$id2));
echo $dm[0]['title'];
}
Run Code Online (Sandbox Code Playgroud)
我在偏移0为1374字节时得到错误.我知道我可以使用embed.ly或JSON解析但我更喜欢PHP.任何有关修复Dailymotion PHP解析的帮助表示赞赏.
您不仅可以更改URL并希望此功能正常运行.
阅读Dailymotion API文档页面,了解如何以编程方式访问视频信息.
作为一个示例,使用REST API,以JSON格式的响应获取视频的标题,获取:
https://api.dailymotion.com/video/xks75n?fields=title
Run Code Online (Sandbox Code Playgroud)
哪个回报
{
"title": "The Farmer and His Sons- Aesop's fables"
}
Run Code Online (Sandbox Code Playgroud)
另一种选择是在问题中使用的URL上使用oEmbed API.
http://www.dailymotion.com/services/oembed?format=json&url=http://www.dailymotion.com/embed/video/xks75n
Run Code Online (Sandbox Code Playgroud)
哪个回报
{
"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
}
Run Code Online (Sandbox Code Playgroud)
提示:您可以使用json_decode()"解码"到PHP对象或数组中来访问值.
| 归档时间: |
|
| 查看次数: |
4242 次 |
| 最近记录: |