DailyMotion无效的授权码

时间:2014-01-19 16:10:04

标签: php api exception authorization

我正在尝试使用以下代码通过DailyMotion PHP SDK发送视频:

<?php
require_once 'dailymotion-sdk-php-master/Dailymotion.php';

$api = new Dailymotion();

$api->setGrantType(Dailymotion::GRANT_TYPE_AUTHORIZATION, '081cf3f9d3f64c8d9234', '98da6430d6ebef2621f1061886ecde1a0aa57def', array('manage_videos'));
try
{
    $url = $api->uploadFile('video.avi');
    $result = $api->call('video.create', array('url' => $url));
}
catch (DailymotionAuthRequiredException $e)
{
    // Redirect the user to the Dailymotion authorization page
    header('Location: ' . $api->getAuthorizationUrl());
    return;
}
catch (DailymotionAuthRefusedException $e)
{
    // Handle case when user refused to authorize
    // <YOUR CODE>
}
?>

我总是收到以下错误:

Fatal error: Uncaught exception 'DailymotionAuthException' with message 'Invalid authorization code.' in /folder/public_html/dailymotion-sdk-php-master/Dailymotion.php:541 Stack trace:
#0 /folder/public_html/dailymotion-sdk-php-master/Dailymotion.php(370): Dailymotion->oauthTokenRequest(Array)
#1 /folder/public_html/dailymotion-sdk-php-master/Dailymotion.php(247): Dailymotion->getAccessToken()
#2 /folder/public_html/dailymotion-sdk-php-master/Dailymotion.php(203): Dailymotion->call('GET /file/uploa...', Array)
#3 /folder/public_html/dailymotion-sdk-php-master/Dailymotion.php(189): Dailymotion->get('/file/upload')
#4 /folder/public_html/index.php(9): Dailymotion->uploadFile('video.avi')
#5 {main} thrown in /folder/public_html/dailymotion-sdk-php-master/Dailymotion.php on line 541

我已尝试过JLepage建议(https://stackoverflow.com/questions/12330141/dailymotion-api-invalid-authorization-code),但没有成功。 有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:0)

我建议您尝试这种方式:

include("Dailymotion.php");

$apiKey = "xxxxxxxxxxxxxxxxxxxx";
$apiSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$username = "yourUsername";
$pwd = "yourPassword";
$filepath = "myVideo.avi";               

$api = new Dailymotion();
$api->setGrantType(Dailymotion::GRANT_TYPE_PASSWORD, $apiKey, $apiSecret, array('manage_videos', 'write','delete'), array('username' => $user, 'password' => $pwd));
$url = $api->uploadFile($filePath);
$result = $api->call('video.create', array(
    'url' => $url,
    'title' => $title,
    'description' => $description,
    'private' => 'false',
    'published' => 'true',
    'channel' => 'lifestyle'
));

重要提示:请勿分享您的API ID!

这对我有用,希望能为你效劳!