DailyMotion Invalid authorization code

守給你的承諾、 提交于 2021-01-29 10:49:22

问题


I'm trying to send videos by DailyMotion PHP SDK with this code:

<?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>
}
?>

I always get the following error:

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

I've tried the JLepage suggestion( https://stackoverflow.com/questions/12330141/dailymotion-api-invalid-authorization-code ), but without success. Anyone can help me, please?


回答1:


I suggest you try this way :

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'
));

Important: Don't share your API's ID!

That works for me, hope that work for you too !



来源:https://stackoverflow.com/questions/21219193/dailymotion-invalid-authorization-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!