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.
Check out NYC's Most Dangerous Intersections Watch the videos
</Developer>

Use Cases

This page provides basic examples showing how to perform simple actions on different graph objects using Dailymotion API.

Video

Creation

  • Using CURL :
# first, get an upload url
curl -i https://api.dailymotion.com/file/upload?access_token=XXX

# then, upload the file
curl -F 'file=@/path/to/video.mp4' [UPLOAD_URL]

# finally, create the video
curl -F 'access_token=XXX' -F 'url=[UPLOAD_URL]' -F 'title=' https://api.dailymotion.com/videos
  • Using PHP SDK :
$url = $api->uploadFile($testVideoFile);

$api->post(
    '/videos',
    array('url'     => $url,
        'title'     => 'PHP SDK test upload',
        'published' => true,
        'channel'   => 'videogames')
);
  • Using JS SDK :
var uploadVideo = function(){
    DM.login(function(response)
    {
        if (response.session)
        {
            // get an upload url
            DM.api('/file/upload', function(response)
            {
                var upload_url = response.upload_url;

                //upload the video and get the url
                var xhr =  new XMLHttpRequest();
                xhr.open('POST', upload_url,true);
                var formData = new FormData(document.getElementById("fileDomId"));
                xhr.send(formData);

                // check when video is uploaded
                xhr.onreadystatechange = function()
                {
                    if (xhr.readyState == 4)
                    {
                        // create the video object and publish the video
                        DM.api('/videos', 'post',
                            { url:JSON.parse(xhr.response).url,
                            title: 'videoTitle', // hardcoded here but should be modified
                            published:'true',
                            channel:'creation' }); // hardcoded here but should be modified
                    }
                }
            });
        }
        else
        {
            console.log("fail " + JSON.stringify(response));
        }
    });
}

Edition

  • Using CURL :
curl -F 'access_token=XXX' -F 'title=New title !' https://api.dailymotion.com/video/[VIDEO_ID]
  • Using PHP SDK :
$api->post(
    '/video/' . $videoId,
    array('title'       => 'New Title',
          'description' => 'New Description')
);
  • Using JS SDK :
var editVideo = function(){
    DM.login(function(response)
    {
        if (response.session)
        {
            // get an upload url
            DM.api('/video/[VIDEO_ID]',
                    'post',
                    {
                        title:'[TITLE]',
                        description: '[DESCRIPTION]'
                    });
        }
        else
        {
            console.log("fail " + JSON.stringify(response));
        }
    });
}

Deletion

  • Using CURL :
curl -X DELETE https://api.dailymotion.com/video/[VIDEO_ID]?access_token=XXX
  • Using PHP SDK :
$api->delete('/video/' . $videoId)
  • Using JS SDK :
var deleteVideo = function(){
    DM.login(function(response)
    {
        if (response.session)
        {
            // get an upload url
            DM.api('/video/[VIDEO_ID]',
                    'delete');
        else
        {
            console.log("fail " + JSON.stringify(response));
        }
    });
}

Comment

Creation

  • Using CURL :
curl -F 'access_token=XXX' -F 'message=New message !' https://api.dailymotion.com/[VIDEO_ID]/comments/[COMMENT_ID]
  • Using PHP SDK :
$api->post('/video/' . $videoId . '/comments',
           array('language' => 'en',
                 'message'  => 'What a nice comment'));
  • Using JS SDK :
var createComment = function(){
    DM.login( function(response)
    {
        if (response.session)
        {
            // post the comment
            DM.api('/video/[VIDEO_ID]/comments',
                'post',
                {message:[COMMENT]});
        }
        else
        {
            console.log("fail: " + JSON.stringify(response));
        }
    }, {scope: 'manage_comments'});
}

Edition

  • Using CURL :
curl -F 'access_token=XXX' -F 'message=New message !' https://api.dailymotion.com/comment/[COMMENT_ID]
  • Using PHP SDK :
$api->post('/comment/x7rv',
           array('message'  => 'New message'));
  • Using JS SDK :
var editComment = function(){
    DM.login( function(response)
    {
        if (response.session)
        {
        // post the comment
        DM.api('/comment/[COMMENT_ID]',
            'post',
            {message:[COMMENT]});
        }
        else
        {
            console.log("fail " + JSON.stringify(response));
        }
    }, {scope: 'manage_comments'});
}

Deletion

  • Using CURL :
curl -X DELETE https://api.dailymotion.com/comment/[COMMENT_ID]?access_token=XXX
  • Using PHP SDK :
$api->delete('/comment/' . $commentId)
  • Using JS SDK :
var deleteComment = function(){
    DM.login( function(response)
    {
        if (response.session)
        {
            // delete the comment
            DM.api('/comment/[COMMENT_ID]','delete');
        }
        else
        {
            console.log("fail " + JSON.stringify(response));
        }
    }, {scope: 'manage_comments'});
}

Playlist

Creation + video addition

  • Using CURL :
curl -F 'access_token=XXX' -F 'name=My Funky Playlist' https://api.dailymotion.com/me/playlists
curl -F 'access_token=XXX' https://api.dailymotion.com/playlist/[PLAYLIST_ID]/videos/[VIDEO_ID]
  • Using PHP SDK :
$result = $api->post('/me/playlists',
                     array('name'        => 'My Funky Playlist',
                           'description' => 'Test of playlist creation from PHP SDK'));

if($result && isset($result['id']))
{
    $api->post('/playlist/' . $result['id'] . '/videos/' . $videoId);
}
  • Using JS SDK :
var createPlaylist = function(){
    DM.login( function(response)
    {
        if (response.session)
        {
            // create the playlist
            DM.api('/me/playlists',
                'post',
                {name:[PLAYLIST_NAME],
                description:[PLAYLIST_DESCRIPTION]},
                function(response)
                {
                    if (response.error) {
                        console.log('could not create playlist: ' + JSON.stringify(response.error));
                    }
                    else {
                        // add a video
                        var playlistId = response.id;
                        DM.api('playlist/'+playlistId + '/videos/[VIDEO_ID]',
                            'post',
                            function(response){
                                if (response.error) console.log('the video could not be added to the playlist ' + JSON.stringify(response.error));
                        });
                    }
            });
        }
        else
        {
            console.log("login failed " + JSON.stringify(response));
        }
    }, {scope: 'manage_playlists'});
}

Edition

  • Using CURL :
curl -F 'access_token=XXX' -F 'name=New playlist name' https://api.dailymotion.com/playlist/[PLAYLIST_ID]
  • Using PHP SDK :
$api->post('/playlist/' . $playlistId,
           array('name' => 'New playlist name'));
  • Using JS SDK :
var editPlaylist = function(){
    DM.login( function(response)
    {
        if (response.session)
        {
            // edit the playlist
            DM.api('/playlist/[PLAYLIST_ID]',
                'post',
                {name:[NEW_NAME]},
                function(response)
                {
                    if (response.error) console.log('could not edit playlist: ' + JSON.stringify(response.error));
            });
        }
        else
        {
            console.log("login failed " + JSON.stringify(response));
        }
    }, {scope: 'manage_playlists'});
}

Deletion

  • Using CURL :
curl -X DELETE https://api.dailymotion.com/playlist/[PLAYLIST_ID]?access_token=XXX
  • Using PHP SDK :
$api->delete('/playlist/' . $playlistId)
  • Using JS SDK :
var deletePlaylist = function(){
    DM.login( function(response)
    {
        if (response.session)
        {
            // delete the playlist
            DM.api('/playlist/[PLAYLIST_ID]',
                'delete',
                function(response)
                {
                    if (response.error) console.log('could not delete playlist: ' + JSON.stringify(response.error));
            });
        }
        else
        {
            console.log("login failed " + JSON.stringify(response));
        }
    }, {scope: 'manage_playlists'});
}

Group

Creation + video addition

  • Using CURL :
curl -F 'access_token=XXX' -F 'name=My Group' -F 'url_name=my_test_group' https://api.dailymotion.com/me/groups
curl -F 'access_token=XXX' https://api.dailymotion.com/group/[GROUP_ID]/videos/[VIDEO_ID]
  • Using PHP SDK :
$result = $api->post('/me/groups',
                     array('name'     => 'My Group',
                           'url_name' => 'my_test_group'));

if($result && isset($result['id']))
{
    $api->post('/group/' . $result['id'] . '/videos/' . $videoId);
}
  • Using JS SDK :
var createGroup = function(){
    DM.login( function(response)
    {
        if (response.session)
        {
            // create the group
            DM.api('/me/groups',
                'post',
                {name:'[GROUP_NAME]',
                url_name:'[URL_NAME]'},
                function(response)
                {
                    if (response.error) {
                        console.log('could not create group: ' + JSON.stringify(response.error));
                    }
                    else {
                        // add a video
                        var groupId = response.id;
                        DM.api('group/'+groupId + '/videos/[VIDEO_ID]', 'post');
                    }
            });
        }
        else
        {
            console.log("login failed " + JSON.stringify(response));
        }
    }, {scope: 'manage_groups'});
}

Edition

  • Using CURL :
curl -F 'access_token=XXX' -F 'name=New group name' https://api.dailymotion.com/group/[GROUP_ID]
  • Using PHP SDK :
$api->post('/group/' . $groupId,
           array('name' => 'New group name'));
  • Using JS SDK :
var editGroup = function(){
    DM.login( function(response)
    {
        if (response.session)
        {
            // edit the group
            DM.api('/group/[GROUP_ID]',
                'post',
                {name:'[NEW_GROUP_NAME]'},
                function(response)
                {
                    if (response.error) console.log('could not edit group: ' + JSON.stringify(response.error));
            });
        }
        else
        {
            console.log("login failed " + JSON.stringify(response));
        }
    }, {scope: 'manage_groups'});
}

Deletion

  • Using CURL :
curl -X DELETE https://api.dailymotion.com/group/[GROUP_ID]?access_token=XXX
  • Using PHP SDK :
$api->delete('/group/' . $groupId)
  • Using JS SDK :
var deleteGroup = function(){
    DM.login( function(response)
    {
        if (response.session)
        {
            // delete the group
            DM.api('/group/[GROUP_ID]',
                'delete',
                function(response)
                {
                    if (response.error) console.log('could not delete group: ' + JSON.stringify(response.error));
            });
        }
        else
        {
            console.log("login failed " + JSON.stringify(response));
        }
    }, {scope: 'manage_groups'});
}

PHP testing environment

Here you can find an example of how to test API actions using simple use-cases

First, create a local_config.php :

require_once 'Dailymotion.php';

// ----- account settings -----//
$apiKey        = 'yourApiKey';
$apiSecret     = 'yourApiSecret';
$testUser      = 'someUser';
$testPassword  = 'yourPassword';
$videoTestFile = '/path/to/video/test.mp4';

//----- scopes you need to run your tests -----//
$scopes = array('userinfo',
                'feed',
                'manage_videos');

//----- Dailymotion object instanciation -----//
$api = new Dailymotion();
$api->setGrantType(
    Dailymotion::GRANT_TYPE_PASSWORD,
    $apiKey,
    $apiSecret,
    array(implode(',', $scopes)),
    array(
        'username' => $testUser,
        'password' => $testPassword
    )
);

Then, include this local_config in your test case script :

require_once 'local_config.php';

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

$result = $api->post(
    '/videos',
    array('url'       => $url,
        'title'     => 'PHP SDK test upload',
        'published' => true,
        'channel'   => 'videogames')
);

var_dump($result);

Table Of Contents