Download the PHP package mmockelyn/dailymotion-php-sdk without Composer
On this page you can find all versions of the php package mmockelyn/dailymotion-php-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mmockelyn/dailymotion-php-sdk
More information about mmockelyn/dailymotion-php-sdk
Files in mmockelyn/dailymotion-php-sdk
Package dailymotion-php-sdk
Short Description Dailymotion PHP SDK
License MIT
Homepage http://dailymotion.com
Informations about the package dailymotion-php-sdk
Dailymotion PHP SDK
This repository contains the official open source PHP SDK that facilitates access to the Dailymotion Graph API from your PHP application. For more information about developing with Dailymotion's services, head to the Developer Area.
Usage
The PHP SDK implements the Dailymotion Advanced API. For a list of all available methods, 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 Graph API overview) as an array
.
Authentication
The Dailymotion 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 /me/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.