2011-10-06 57 views
1

任何人都可以幫我整合DailyMotion API嗎?我使用他們的SDK但無濟於事,論壇也沒有多大幫助。如何使用DailyMotion API?

+0

你要問一個更具體的問題...... –

+0

http://catb.org/~esr/faqs/smart-questions.html –

回答

3

我試過使用DailyMotion SDK。它工作得很好,但後來出於某種原因,我被告知不使用SDK。所以這裏是使用cURL使用API​​的PHP代碼。

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 '[email protected]$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); 
} 
+0

這段代碼是否仍然有效? $ res = json_decode($ output);對我沒有任何回報。 – user1017063

+0

是的,它是有效的。我的腳本運行得很好。請確保您使用適當的憑據和變量,如視頻路徑位置。 – kanchan

+0

在腳本中添加此行以及 curl_setopt($ curlInit,CURLOPT_SSL_VERIFYPEER,false); –