We use cookies to offer an improved online experience and offer you content and services adapted to your interests.
By using Dailymotion, you are giving your consent to our cookies.
Watch Grace Weber Perform Her New Song "As Long As I Wander" Watch the videos
</Developer>

PHP SDK

The PHP SDK is available on GitHub.

Usage

The PHP SDK implements the Dailymotion Advanced API. For a list of all available methods, see API Reference. To call a method using the PHP SDK, use the get, post or delete methods as follow:

<?php

$api = new Dailymotion();
$result = $api->get('/videos', array('fields' => array('id', 'title', 'owner_screenname')));

The $result variable contains the result of the method as described in the API reference as an array.

Authentication

The Dailymotion API requires OAuth 2.0 authentication in order to be used. This library implements three granting methods of OAuth 2.0 for different kind of usages.

Token Grant Type

This grant type is the one you should use in most cases. With this grant type you redirect the user to an authorization page on Dailymotion, and your script is called back once the end-user authorized your API key to access the Dailymotion service on its behalf.

Here is a usage example:

<?php

$api = new Dailymotion();
$api->setGrantType(Dailymotion::GRANT_TYPE_TOKEN, $apiKey, $apiSecret)

try
{
    $result = $api->get('/me/videos', array('fields' => 'id,title,description'));
}
catch (DailymotionAuthRequiredException $e)
{
    // Redirect the user to the Dailymotion authorization page
    header('Location: ' . $api->getAuthorizationUrl());
    return;
}
catch (DailymotionAuthRefusedException $e)
{
    // Handle case when user refused to authorize
    // <YOUR CODE>
}

Password Grant Type

If your PHP application isn’t a web application and cannot redirect the user to the Dailymotion authorization page, the password grant type can be used. With this grant type you have the responsibility to ask the user for its credentials. Make sure you API secret remains secret though.

Here is a usage example:

<?php

$api = new Dailymotion();

if (!isset($_POST['username']) || !isset($_POST['password']))
{
    // Ask end-user's credentials
    // <YOUR CODE>
}
else
{
    $api->setGrantType(Dailymotion::GRANT_TYPE_PASSWORD, $apiKey, $apiSecret, null,
                       array('username' => $_POST['username'], 'password' => $_POST['password']));

    $result = $api->get('/me/videos', array('fields' => 'id,title,description'));
}

Client Credentials Grant Type

If you don’t need to access the Dailymotion API on behalf of a user because, for instance, you plan to only access public data, you can use the CLIENT_CREDENTIALS grant type. With this grant type, you will only have access to public data or private data of the user owning the API key.

Here is a usage example:

<?php

$api = new Dailymotion();
$api->setGrantType(Dailymotion::GRANT_TYPE_CLIENT_CREDENTIALS, $apiKey, $apiSecret);
$result = $api->get('/videos', array('fields' => 'id,title,description'));

Upload File

Certain methods like POST /me/videos requires a URL to a file. To create those URLs, the uploadFile(): method have to be used like this:

<?php

$url = $api->uploadFile($filePath);

You can then use this URL as an argument to methods requiring such parameter. For instance to create a video:

<?php

$result = $api->post('/me/videos', array('url' => $url, 'title' => $videoTitle, ...));

Table Of Contents