2

I would like to use dailymotion api to get infos of my own private videos. SO ... I have a Dailymotion account I have created an API key and secret key I downloaded the PHP class I would like to get infos of my privates videos to diplay it on my website...

So i think I need to authenticate my account and after get the code... but it does not work :'( Please could you give me a sample code to do this ?

my test code is like that for now

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

and the result is : This user is not allowed to access this video.

so i think there is a problem with authentication ... but i do not understant how to do that only with php

thanks a lot for your help

yoyoy
  • 21
  • 1

1 Answers1

0

It looks like there are a couple of issues in your code and in the way you authenticate:

1) your code: you call $api = new Dailymotion(); and then set the authorization grant type with your api key and secret. But next line, you override all that by re-writing $api = new Dailymotion();. So I recommend you to remove this line, otherwise it is like you have not set any grant type!

2) There is an interesting code sample regarding authorization grant type in php, doing exactly what you're trying to do, at https://developer.dailymotion.com/tools/sdks#sdk-php-grant-authorization Your code is very similar, why did you comment the return header('Location: ' . $api->getAuthorizationUrl()); part when catching DailymotionAuthRequiredException ? This part redirects the user to the auth page so he/she can authenticate. I also recommend to have a look at others grant types for authentication, such as password grant type (https://developer.dailymotion.com/tools/sdks#sdk-php-grant-password)

dailymotion
  • 1,546
  • 1
  • 9
  • 11