Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 96 lines (67 sloc) 3.004 kb
d436f6e @rs Initial Revision
rs authored
1 Dailymotion PHP SDK
2 ===================
3
4 This repository contains the official open source PHP SDK that allows you to access the Dailymotion
5 API from your website.
6
7 Usage
8 -----
9
11ef349 @rs Add file upload support
rs authored
10 ### Authentication
11
d436f6e @rs Initial Revision
rs authored
12 The Dailymotion API requires OAuth 2.0 authentication in order to be used. This library implements
13 three granting methods of OAuth 2.0 for different kind of usages.
14
11ef349 @rs Add file upload support
rs authored
15 #### Token Grant Type
d436f6e @rs Initial Revision
rs authored
16
7827de2 @rs Handle API requests with no auth
rs authored
17 This mode is the mode you should use in most cases. In this mode you redirect the user to an
18 authorization page on Dailymotion, and you script is called back once the end-user authorized your API
d436f6e @rs Initial Revision
rs authored
19 key to access the Dailymotion service on its behalf.
20
21 Here is a usage example:
22
23 <?php
24
7827de2 @rs Handle API requests with no auth
rs authored
25 $api = new Dailymotion();
26 $api->setGrantType(Dailymotion::GRANT_TYPE_TOKEN, $apiKey, $apiSecret)
d436f6e @rs Initial Revision
rs authored
27
28 try
29 {
30 $result = $api->call($method, $arguments);
31 }
32 catch (DailymotionAuthRequiredException $e)
33 {
34 // Redirect the user to the Dailymotion authorization page
35 header('Location: ' . $api->getAuthorizationUrl());
36 return;
37 }
38 catch (DailymotionAuthRefusedException $e)
39 {
7827de2 @rs Handle API requests with no auth
rs authored
40 // Handle case when user refused to authorize
d436f6e @rs Initial Revision
rs authored
41 // <YOUR CODE>
42 }
43
11ef349 @rs Add file upload support
rs authored
44 #### Password Grant Type
d436f6e @rs Initial Revision
rs authored
45
46 If you PHP application isn't a web application and cannot redirect the user to the Dailymotion
47 authorization page, the password grant type can be used. With this grant type you have the
48 responsibility to ask the user for its credentials. Make sure you API secret remains secret though.
49
50 <?php
51
7827de2 @rs Handle API requests with no auth
rs authored
52 $api = new Dailymotion();
d436f6e @rs Initial Revision
rs authored
53
7827de2 @rs Handle API requests with no auth
rs authored
54 if (!isset($_POST['username']) || !isset($_POST['password']))
d436f6e @rs Initial Revision
rs authored
55 {
7827de2 @rs Handle API requests with no auth
rs authored
56 // Ask end-user's credentials
57 // <YOUR CODE>
d436f6e @rs Initial Revision
rs authored
58 }
7827de2 @rs Handle API requests with no auth
rs authored
59 else
d436f6e @rs Initial Revision
rs authored
60 {
7827de2 @rs Handle API requests with no auth
rs authored
61 $api->setGrantType(Dailymotion::GRANT_TYPE_PASSWORD, $apiKey, $apiSecret, null,
62 array('username' => $_POST['username'], 'password' => $_POST['password']));
63
d436f6e @rs Initial Revision
rs authored
64 $result = $api->call($method, $arguments);
65 }
66
67
11ef349 @rs Add file upload support
rs authored
68 #### None Grant Type
d436f6e @rs Initial Revision
rs authored
69
70 If you don't need to access the Dailymotion API on behalf of a user because, for instance, you plan to
71 only access public data, you can use the NONE grant type. With this grant type, you will only have
72 access to public data or private date of the user owning the API key.
73
74 <?php
75
7827de2 @rs Handle API requests with no auth
rs authored
76 $api = new Dailymotion();
77 $api->setGrantType(Dailymotion::GRANT_TYPE_NONE, $apiKey, $apiSecret);
d436f6e @rs Initial Revision
rs authored
78 $result = $api->call($method, $arguments);
79
11ef349 @rs Add file upload support
rs authored
80 ### File Upload
81
82 Certain methods like `video.upload` requires a URL to a file. To create those URLs, the `uploadFile:delegate:` method have to be used like this:
83
84 $url = $api->uploadFile($filePath);
85
86 You can then use this URL as an argument to methods requiring such parameter. For instance to create a video:
87
88 $result = $api->call('video.create', array('url' => $url));
89
d436f6e @rs Initial Revision
rs authored
90 Feedback
91 --------
92
93 We are relying on the [GitHub issues tracker][issues] linked from above for feedback. File bugs or
94 other issues [here][issues].
95
96 [issues]: http://github.com/dailymotion/dailymotion-sdk-php/issues
Something went wrong with that request. Please try again.