php - 未捕获的 Dailymotion 身份验证要求异常
问题描述
我正在尝试使用 Dailymotion API。我遵循了所有可能的指示,但我不断收到错误,尽管我正在使用人们在其他帖子中建议的更改,即。DailyMotion 无效的授权码
我得到的错误
致命错误:/Library/WebServer/Documents/basic/Dailymotion.php:582 中未捕获的 DailymotionAuthRequiredException 堆栈跟踪:
0 /Library/WebServer/Documents/basic/Dailymotion.php(404): Dailymotion->getAccessToken()
1 /Library/WebServer/Documents/basic/Dailymotion.php(356): Dailymotion->call('GET /file/uploa...', Array)
2 /Library/WebServer/Documents/basic/Dailymotion.php(326): Dailymotion->get('/file/upload', Array)
3 /Library/WebServer/Documents/basic/index.php(12): Dailymotion->uploadFile(NULL)
4 {main} 在第 582 行的 /Library/WebServer/Documents/basic/Dailymotion.php 中抛出
我在我的 php 中遗漏了什么吗?我还没有看到任何人引用 getAccessToken。
<?
include("Dailymotion.php");
$apiKey = "xxxxxxxxxxxxxxx";
$apiSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
$user = "my username";
$pwd = "my password";
$filepath = "Test.mp4";
$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',
));
?>
解决方案
想出了答案,我一直假设人们的答案是一样的。我没有意识到我必须把它放到另一个位来授权我的帐户。
require_once 'Dailymotion.php';
// Account settings
$apiKey = 'your apikey';
$apiSecret = 'your secret';
$testUser = 'your username';
$testPassword = 'your password';
// Scopes you need to run your tests
$scopes = array(
'manage_videos',
);
// Dailymotion object instanciation
$api = new Dailymotion();
$api->setGrantType(Dailymotion::GRANT_TYPE_AUTHORIZATION, $apiKey, $apiSecret);
try
{
// The following line will actually try to authenticate before making the API call.
// * The SDK takes care of retrying if the access token has expired.
// * The SDK takes care of storing the access token itself using its `readSession()`
// and `storeSession()` methods that are made to be overridden in an extension
// of the class if you want a different storage than provided by default.
$url = $api->uploadFile('Test.mp4');
$result = $api->call('video.create', array(
'url' => $url,
'title' => 'prove this works',
'description' => 'THis is purely a test',
'private' => 'false',
'published' => 'true'
));
var_dump($result);
}
catch (DailymotionAuthRequiredException $e)
{
// If the SDK doesn't have any access token stored in memory, it tries to
// redirect the user to the Dailymotion authorization page for authentication.
return header('Location: ' . $api->getAuthorizationUrl());
}
catch (DailymotionAuthRefusedException $e)
{
}
?>
推荐阅读
- c# - 由于版本号不匹配,无法加载程序集
- c# - C# WinForms,具有半透明背景的工具提示
- sql - 将一个字段等分为2
- java - 蓝牙数据传输
- google-cloud-platform - 带有授权 API 密钥的 Google URL Shorter API 返回 403
- ios - WKWebView 从 Bundle 和 Document 目录加载文件
- grafana - 如何关闭表grafana中的自动生成列
- selenium - 如何在一个浏览器中运行相同功能文件的所有场景?使用硒,Java,黄瓜
- java - 带有 TLS 的 REST 客户端返回 SSLHandshakeException:收到致命警报:handshake_failure
- sql - SQL Server 2014 - 模拟和 CTE 循环