How do I use the DailyMotion API? [closed]
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 开发者_Go百科8 years ago.
Improve this questionCan anyone here help me with the integration of the DailyMotion API? I am using their SDK but to no avail, and forums are also not helping much.
I tried using the DailyMotion SDK. It worked very well but later on for some reason I was told not to use SDKs. So here is the PHP code to use the API using cURL.
define("DAILYMOTION_API_KEY", "xyzzz");
define("DAILYMOTION_API_SECRET_KEY", "abcc");
$testUser = "username";
$testPassword = "pwd";
$url = 'https://api.dailymotion.com/oauth/token';
$testVideoFile = "<file location>";
$vidName = "testing video";
$vidDesc = "this is a test";
/* GET ACCESS TOKEN */
try {
$data = "grant_type=password&client_id=" . DAILYMOTION_API_KEY . "&client_secret=" . DAILYMOTION_API_SECRET_KEY . "&username=abs&password=pwd&scope=read+write";
$curlInit = curl_init($url);
curl_setopt($curlInit, CURLOPT_POST, 1);
curl_setopt($curlInit, CURLOPT_POSTFIELDS, $data);
curl_setopt($curlInit, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curlInit);
curl_close($curlInit);
$res = json_decode($output);
$accessToken = $res->access_token;
$getUploadUrl = "curl -d 'access_token=$accessToken' -G https://api.dailymotion.com/file/upload/";
$uploadUrl = json_decode(system($getUploadUrl));
$postFileCmd = "curl -F 'file=@$testVideoFile'" . ' "' . $uploadUrl->upload_url . '"';
$postFileResponse = json_decode(system($postFileCmd));
$postVideoCmd = "curl -d 'access_token=$accessToken&url=$postFileResponse->url' https://api.dailymotion.com/me/videos";
$postVideoResponse = json_decode(system($postVideoCmd));
$videoId = $postVideoResponse->id;
$publishCmd = "curl -F 'access_token=$accessToken' \
-F 'title=$vidName' \
-F 'published=true' \
-F 'description=this is a test' \
https://api.dailymotion.com/video/$videoId";
$publishres = system($publishCmd);
print_r($publishres);
echo "Video is posted & published Successfully";
} catch (Exception $e) {
print_r($e);
}
精彩评论