dailymotion API PHP 问题

发布于 2024-12-03 19:53:10 字数 558 浏览 0 评论 0原文

以下代码适用于 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 解析的帮助将不胜感激。

The following code works for Vimeo API:

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

If for Dailymotion I use:

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

I get Error at offset 0 of 1374 bytes. I know I can use embed.ly or JSON parsing but I prefer PHP. Any help concerning repair of Dailymotion PHP parsing is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

尽揽少女心 2024-12-10 19:53:10

您不能只更改 URL 并期望它起作用。

通读 Dailymotion API 文档页面,了解如何以编程方式访问视频信息。

举个例子,使用 REST API,要以 JSON 格式的响应获取视频标题,请 fetch:

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

返回

{
    "title": "The Farmer and His Sons- Aesop's fables"
}

另一个选项是使用 oEmbed API 位于问题中的 URL 上。

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

返回

{
    "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
}

提示:您可以使用 json_decode() 将其“解码”为 PHP用于访问值的对象或数组。

You can't just change URLs and expect this to work.

Read through the Dailymotion APIs documentation pages to learn how to access video information programatically.

As one example, using the REST API, to get the title of your video in a JSON formatted response, fetch:

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

Which returns

{
    "title": "The Farmer and His Sons- Aesop's fables"
}

Another option is to use the oEmbed API on the URL you have in the question.

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

Which returns

{
    "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
}

Hint: you can use json_decode() to "decode" that into a PHP object or array to access the value(s).

懵少女 2024-12-10 19:53:10

你可能会有更好的运气

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

You might have better luck with

'https://api.dailymotion.com/video/'. $id2 .'?fields=title'
水晶透心 2024-12-10 19:53:10

如果您使用 php,最简单的方法是使用 Dailymotion PHP SDK:
https://github.com/dailymotion/dailymotion-sdk-php

<?php
$api = new Dailymotion();
$result = $api->get('/video/' . $id, array('fields' => array('title', 'channel'...)));

If you use php the easy way is to use Dailymotion PHP SDK :
https://github.com/dailymotion/dailymotion-sdk-php

<?php
$api = new Dailymotion();
$result = $api->get('/video/' . $id, array('fields' => array('title', 'channel'...)));
少女的英雄梦 2024-12-10 19:53:10

Dailymotion 拥有出色的 API 文档

尝试

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

Dailymotion have great API Documentation.

Try

https://api.dailymotion.com/video/'. $id2 .'?fields=title
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文