Download the PHP package dailymotion/sdk without Composer
On this page you can find all versions of the php package dailymotion/sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dailymotion/sdk
More information about dailymotion/sdk
Files in dailymotion/sdk
Package sdk
Short Description Dailymotion PHP SDK
License MIT
Homepage http://dailymotion.com
Informations about the package sdk
Dailymotion PHP SDK
PHP SDK Documentation: https://developers.dailymotion.com/sdk/platform-sdk/php/
This repository contains the official open source PHP SDK that facilitates access to the Dailymotion Platform API from your PHP application. For more information about developing with Dailymotion's services, head to the Developer Portal.
Usage
The PHP SDK implements the Dailymotion Platform API. For a list of all available objects, fields and filters, see the complete API reference. To call a method using the PHP SDK, use the get
, post
or delete
methods as follow:
The $result
variable contains the result of the method (as described in the Platform API basics) as an array
.
Authentication
The Platform API requires OAuth 2.0 authentication in order to access protected resources.
Contrary to most OAuth SDKs, the Dailymotion PHP SDK implements lazy authentication, which means that no authentication request is sent as long as no data is requested from the API. At which point, two requests are sent back-to-back during the first request for information, one to authenticate and one to fetch the data. Keep this in mind while working through the rest of the documentation.
Please note that the Dailymotion PHP SDK also takes care of abstracting the entire OAuth flow, from retrieving, storing and using access tokens, to using refresh tokens to gather new access tokens automatically. You shouldn't have to deal with access tokens manually but if you have to, at the programming-level, the SDK exposes this information with the Dailymotion::getSession()
and Dailymotion::setSession()
methods. At the OAuth-level, a session is the response sent by the OAuth server when successfully authenticated, for example:
Note: One of the problems with OAuth 2.0 is that the specification doesn't offer any mechanism to upgrade the scope of an existing session. To add new scopes to an already existing session, you first need to call the Dailymotion::logout()
method and start a new session with your new list of scopes.
If you really wish to manually retrieve an access token without waiting for the SDK to take care of it when sending the first query, you can use the Dailymotion::getAccessToken()
method. It will try to authenticate and return you the corresponding access token or an exception. Please note that this isn't the recommended way to proceed. See the Overloading the SDK section for more information about handling access tokens.
This library implements three OAuth 2.0 granting methods for different kind of usages.
Authorization 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 application is called back once the end-user authorized your API key to access Dailymotion on his/her behalf.
Here is a usage example:
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 instead of the authorization one. With this grant type you have the responsibility to ask the user for its credentials. Make sure your API secret remains secret though, do not use this kind of authentication for any service that is running on the client if you do not want your API secret to be publicly exposed.
Here is a usage example:
Client Credentials Grant Type
If you don't need to access the Dailymotion API on behalf of someone else because, for instance, you only plan to access public data, you can use the client credentials grant type. With this grant type, you will only have access to public data or data protected by a specific scope and/or role. It's the equivalent of being unlogged but having the permission (granted by Dailymotion as part of a partners program or similar) to access sensitive data.
Here is a usage example:
There is no authenticated user in this scenario, thus you won't be able to access the /me
endpoint.
Upload File
Some methods like POST /user/<CHANNEL_ID>/videos
requires a URL to a file.
To create those URLs, Dailymotion offers a temporary upload service through the Dailymotion::uploadFile()
method which can be used like this:
You can then use this $url
result as an argument to methods requiring such a parameter.
For instance to create a video:
You can also retrieve a progress URL like this:
Hitting this URL after the upload has started allows you to monitor the upload progress.
Overloading the SDK
As stated in the Authentication section above, the PHP SDK takes care of abstracting the entire OAuth flow, from retrieving, storing and using access tokens, to using refresh tokens to gather new access tokens automatically.
Overloading the SDK with your own implementation allows you to adapt the SDK behaviour to your needs. The most common usage is to overload both Dailymotion::storeSession()
and Dailymotion::readSession()
methods to change the default storage system (which uses cookies).
Here is a crude example of overloading the SDK to store sessions (access token + refresh token) on the file system instead of using cookies (for a command line program for example):
Don't hesitate to extend the functionalities of the SDK and send us pull requests once you're done! And again, if you think that something's wrong, don't hesitate to report any issue.