To enjoy all our Developer Portal features, please switch to Microsoft Edge, Google Chrome or Mozilla Firefox browsers.

How to programmatically upload videos via Dailymotion's API using our PHP SDK

Posted on by Nicolas Ferron

Using our SDKs is the fastest and easiest way to programmatically upload videos on Dailymotion. Follow this PHP tutorial to learn how to add a video on our servers and link it to your channel. 

Prerequisites: to upload videos you have to become a Partner of Dailymotion and create an API key in your Partner Space.

Step 1: Authentication on Dailymotion via our API

First of all, you need to authenticate yourself through the API to the Dailymotion account on which the video is going to belong to and request the manage_videos scope. 

Code sample

require_once 'Dailymotion.php';
// Account settings
$apiKey        = 'yourApiKey';
$apiSecret     = 'yourApiSecret';
$testUser      = 'someUser';
$testPassword  = 'yourPassword';

// Scopes you need to run your tests
$scopes = array(
    'manage_videos',
);
// Dailymotion object instanciation
$api = new Dailymotion();
$api->setGrantType(
    Dailymotion::GRANT_TYPE_PASSWORD,
    $apiKey,
    $apiSecret,
    $scopes,
    array(
        'username' => $testUser,
        'password' => $testPassword,
    )
);

See our authentication guide

Step 2: Upload a video on Dailymotion with our PHP SDK

The PHP SDK implements Dailymotion’s API and allows you to upload videos on our platform in 2 steps (upload/creation).

Code sample

// 1. Upload your file on Dailymotion's servers
$url = $api->uploadFile('/path/to/your/video.mp4');

// 2. Create the video on your channel
$api->post(
    '/videos',
    array(
        'url'       => $url,
        'title'     => 'Dailymotion PHP SDK upload test',
        'tags'      => 'dailymotion,api,sdk,test',
        'channel'   => 'videogames',
        'published' => true, 
    )
);

Select 'published' => false in case you don’t want to publish the video immediately.

Find our PHP SDK on GitHub.

Not coding in PHP? 

Visit Dailymotion’s SDKs documentation and find your own language!