Search code examples
phpdailymotion-api

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


I need to embed a private dailymotion video with 'dailymotion-sdk-php'. I created an account and added a key and secret. But inside iframe I only get 'Private content' message.

This is my code,

<?php 
error_reporting(E_ALL & ~E_NOTICE);
ini_set('display_errors', 1);
set_time_limit(0);

$apiKey = 'my key';
$apiSecret = 'my secret';
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/my id',
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>';

echo '<iframe frameborder="0" width="480" height="270" src="http://www.dailymotion.com/embed/video/my id"></iframe>';
}
?>

It would be great if someone can help me to archive this


Solution

  • When you have a private video, and you want to embed it on your site, you need to do so with its private id. The API will return you this id, under the private_id field (you need to be authenticated as the owner of the video). Also, you can directly get the embed url using the embed_url, or you can even get the embed_html.

    Example of an API call you can use: https://api.dailymotion.com/video/ID?fields=embed_html,embed_url,private,private_id&access_token=TOKEN

    Get more info on private videos at https://developer.dailymotion.com/api/faq#difference-private-public-videos

    Note: when you embed a private video, you disclose its private id. Beware that the video is not fully private anymore as anyone can get this id!