如何使用dailymotion api获取私人视频的iframe代码


How to get the iframe code for a private video with dailymotion api

我想使用dailymotion api来获取我自己的私人视频的信息。所以。。。我有一个Dailymotion账户我已经创建了一个API密钥和密钥我下载了PHP类我想得到我的私人视频的信息,把它放在我的网站上。。。

所以我想我需要验证我的帐户,在得到代码后。。。但它不起作用:(你能给我一个样本代码吗?

我的测试代码现在是这样的

<?php 
error_reporting(E_ALL & ~E_NOTICE);
ini_set('display_errors', 1);
$apiKey = 'xxxx';
$apiSecret = 'xxxx';
require_once 'Dailymotion.php';
// Instanciate the PHP SDK.
$api = new Dailymotion();
// Tell the SDK what kind of authentication you'd like to use.
// Because the SDK works with lazy authentication, no request is performed at this point.
$api->setGrantType(Dailymotion::GRANT_TYPE_AUTHORIZATION, $apiKey, $apiSecret);
$api = new Dailymotion();
try
{
$result = $api->get(
'/video/privateVideoId',
array('fields' => array('id', 'title', 'owner'))
);
}
catch (DailymotionAuthRequiredException $e)
{
echo $e->getMessage();
// If the SDK doesn't have any access token stored in memory, it tries to
// redirect the user to the Dailymotion authorization page for authentication.
//return header('Location: ' . $api->getAuthorizationUrl());
}
catch (DailymotionAuthRefusedException $e)
{
echo $e->getMessage();
// Handle the situation when the user refused to authorize and came back here.
// <YOUR CODE>
}
trace($result);
function trace($d) {
echo '<pre>';
var_dump($d);
echo '</pre>';
}
?>

结果是:不允许此用户访问此视频。

所以我认为身份验证有问题。。。但我不知道如何做到这一点只有php

非常感谢您的帮助

您的代码和身份验证方式似乎存在一些问题:

1) 您的代码:您调用$api = new Dailymotion();,然后使用您的api密钥和secret设置授权授予类型。但下一行,您可以通过重写$api = new Dailymotion();来覆盖所有这些。所以我建议你删除这一行,否则就像你没有设置任何授予类型!

2) php中有一个关于授权授予类型的有趣代码示例,它正是您想要做的事情,位于https://developer.dailymotion.com/tools/sdks#sdk-php授权您的代码非常相似,为什么在捕获DailymotionAuthRequiredException时注释return header('Location: ' . $api->getAuthorizationUrl());部分?此部分将用户重定向到身份验证页面,以便他/她可以进行身份验证。我还建议查看其他用于身份验证的授予类型,例如密码授予类型(https://developer.dailymotion.com/tools/sdks#sdk-php授予密码)