---
updatedAt: 2026-07-27T10:11:15.000Z
agentTools:
  projectIndex: https://developers.dailymotion.com/v0/llms.txt
---

# PHP SDK

<br />

The PHP SDK provides access to the features of the [Platform API](https://developers.dailymotion.com/v0/reference/password-method).

It is available on [GitHub](https://github.com/dailymotion/dailymotion-sdk-php).
Feel free to [report any issue](https://github.com/dailymotion/dailymotion-sdk-php/issues) or send [pull requests](https://github.com/dailymotion/dailymotion-sdk-php/pulls) there.

***

## Overview

**The PHP SDK implements the Dailymotion [Platform API](https://developers.dailymotion.com/v0/reference/password-method).** For a list of all available methods, see the complete [API reference](https://developers.dailymotion.com/v0/reference/web-sdk-player-methods).

To call a method using the PHP SDK, use the `GET`, `POST` or `DELETE` methods as follows:

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

The `$result` variable contains the result of the method (as described in the [response types](https://developers.dailymotion.com/v0/reference/understand-the-different-data-types)) as an array.

***

## Authentication

The Platform API requires OAuth 2.0 authentication in order to be used.

Contrary to most OAuth SDKs, the Dailymotion PHP SDK implements **lazy authentication**, meaning no authentication request is sent until data is actually requested. When that happens, two requests are sent back-to-back during the first attempted API call: one to authenticate, one to fetch the data.

**The Dailymotion PHP SDK also abstracts the entire OAuth flow**, from retrieving, storing and using access tokens, to automatically refreshing them. If needed, access tokens can still be handled manually using `Dailymotion::getSession()` and `Dailymotion::setSession()`.

Example of a session returned by the OAuth server:

```json
{
    "access_token": "<ACCESS_TOKEN>",
    "token_type": "Bearer",
    "expires_in": 36000,
    "refresh_token": "<REFRESH_TOKEN>",
    "scope": "<SCOPE1 SCOPE2 SCOPE3>",
    "uid": "<USER_ID>"
}
```

**Note:** OAuth 2.0 does not support upgrading scopes on an existing session. To request new scopes, you must call `Dailymotion::logout()` and restart a new session.

If you wish to retrieve an access token manually (not recommended), use `Dailymotion::getAccessToken()`.

The library supports three OAuth 2.0 grant types.

### Authorization grant type

This grant type should be used in most cases. Users are redirected to the Dailymotion authorization page and your application receives a callback once access is granted.

```php
// Instantiate the PHP SDK.
$api = new Dailymotion();

// Choose the authentication grant type.
$api->setGrantType(Dailymotion::GRANT_TYPE_AUTHORIZATION, $apiKey, $apiSecret);

try {
    $result = $api->get(
        '/me/videos',
        array('fields' => array('id', 'title', 'owner')
    );
}
catch (DailymotionAuthRequiredException $e) {
    return header('Location: ' . $api->getAuthorizationUrl());
}
catch (DailymotionAuthRefusedException $e) {
    // Handle user refusal
}
```

### Password grant type

Use this when your PHP application cannot redirect the user (e.g. CLI scripts). You must collect user credentials yourself. **Never expose the API secret.**

```php
$api = new Dailymotion();

if (empty($_POST['username']) || empty($_POST['password'])) {
    // Ask for credentials
} else {
    $api->setGrantType(
        Dailymotion::GRANT_TYPE_PASSWORD,
        $apiKey,
        $apiSecret,
        array(),
        array(
            'username' => $_POST['username'],
            'password' => $_POST['password'],
        )
    );

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

### Client Credentials grant type

Use this when you do not need access on behalf of a user. This gives access only to public data or data permitted by your scopes/roles.

```php
$api = new Dailymotion();
$api->setGrantType(Dailymotion::GRANT_TYPE_CLIENT_CREDENTIALS, $apiKey, $apiSecret);

$result = $api->get(
    '/videos',
    array('fields' => array('id', 'title', 'owner'))
);
```

No authenticated user exists, so `/me` endpoints cannot be accessed.

***

## Upload File

Some methods like `POST /me/videos` require a file URL. The SDK provides a temporary upload helper using `Dailymotion::uploadFile()`.

```php
$url = $api->uploadFile($filePath);
var_dump($url);
```

Then use this URL when creating a video:

```php
$result = $api->post(
    '/me/videos',
    array(
        'url' => $url,
        'title' => $videoTitle,
        'channel' => $channel,
        'published' => true,
        'is_created_for_kids' => false
    )
);
```

Retrieve a progress URL:

```php
$progressUrl = null;
$url = $api->uploadFile($filePath, null, $progressUrl);
var_dump($progressUrl);
```

Querying this URL lets you monitor the upload progress.

***

## Overloading the SDK

You can override the SDK to customize OAuth handling. Commonly, developers override `Dailymotion::storeSession()` and `Dailymotion::readSession()` to change the default cookie storage.

Example using a file-based session for CLI environments:

```php
class DailymotionCli extends Dailymotion
{
    protected static $sessionFile;

    public function __construct()
    {
        self::$sessionFile = __DIR__ . '/api-session.json';
    }

    protected function readSession()
    {
        $session = json_decode(file_get_contents(self::$sessionFile), true);
        return $session;
    }

    protected function storeSession(array $session = array())
    {
        file_put_contents(self::$sessionFile, json_encode($session), LOCK_EX);
        return $this;
    }
}
```

Feel free to extend the SDK and submit [pull requests](https://github.com/dailymotion/dailymotion-sdk-php/pulls). If you spot any issue, [open a ticket](https://github.com/dailymotion/dailymotion-sdk-php/issues).