我正在尝试使用Dropbox PHP设置基本身份验证示例,但我失败了。当我启动index.php时,我被重定向到dropbox登录。然后,一旦我登录,我就会被重定向回dropbox_finish.php
,我有state
和code
,例如:
?state=bKwCAATDb7A5JLHmCj8wgA%3D%3D&code=YQb8c261HlAAAAAAAAAAXAK1OOk6DqK-RtqnJ_SG0F0
比我收到此错误:
[Mon May 25 00:27:39.074399 2015] [:error] [pid 5459] [客户 127.0.0.1:44489] PHP致命错误:带有消息'HTTP状态的未捕获异常'Dropbox \ Exception_BadRequest' 400 \ n {“error_description”:“无效的client_id或client_secret”, “error”:“invalid_client”}'in /var/www/php/oauth/vendor/dropbox/dropbox-sdk/lib/Dropbox/RequestUtil.php:250\nStack 追踪:\ n#0 /var/www/php/oauth/vendor/dropbox/dropbox-sdk/lib/Dropbox/WebAuthBase.php(39): 收存箱\ RequestUtil :: unexpectedStatus(对象(保管箱\的HttpResponse))\ n#1 /var/www/php/oauth/vendor/dropbox/dropbox-sdk/lib/Dropbox/WebAuth.php(270): 收存箱\ WebAuthBase-> _finish( 'YQb8c261HlAAAAA ...', 'https://oauth.d ...')\ N#2 /var/www/php/oauth/web/dropbox_finish.php(4): Dropbox \ WebAuth->完成(数组)\ n#3 {main} \ n抛出 /var/www/php/oauth/vendor/dropbox/dropbox-sdk/lib/Dropbox/RequestUtil.php 在第250行
我一直试图设置一些尽可能基本的东西,暂时开始一段时间没有结果。任何帮助将不胜感激。
这是我的代码index.php
:
include_once __DIR__.'/../app/start.php';
include_once __DIR__.'/../app/dropbox_auth.php';
然后start.php
:
session_start();
$_SESSION['user_id'] = 1;
require_once __DIR__.'/../vendor/autoload.php';
$key = "fttwagu78r37ped";
$secret = "fttwagu78r37ped";
$GLOBALS['app_name'] = "oauth-php/1.0";
$GLOBALS['redirectURI'] = "https://oauth.dev/dropbox_finish.php";
$GLOBALS['HomeURI'] = "https://oauth.dev";
$appInfo = new Dropbox\AppInfo($key, $secret);
//CSRF Cross Site Request Forgery protection.
$csrfTokenStore = new Dropbox\ArrayEntryStore($_SESSION, 'dropbox-auth-csrf-token');
$webAuth = new Dropbox\WebAuth($appInfo, $GLOBALS['app_name'], $GLOBALS['redirectURI'], $csrfTokenStore);
$db = new PDO('mysql:host=localhost;dbname=oauth','root','root');
$user = $db->prepare("SELECT * FROM user WHERE id = :user_id");
$user->execute(['user_id' => $_SESSION['user_id']]);
$user = $user->fetchObject();
文件dropbox_auth.php
:
if ($user->token){
$client = new Dropbox\Client($user->token, $GLOBALS['app_name'], 'UTF-8');
$client->getAccountInfo();
} else {
$authURL = $webAuth->start();
header("Location: $authURL");
exit();
}
Dropbox完成文件dropbox_finish.php
:
require_once "../app/start.php";
list($accessToken) = $webAuth->finish($_GET);
$store = $db->prepare("UPDATE user SET token = :dropbox_token"
. "WHERE id = :user_id");
$store->execute(['dropbox_token' => $accessToken,
'user_id' => $_SESSION['user_id']]);
header("Location: ".$GLOBALS['HomeURI']);
作为额外的细节,只是说我在MySQL中有这个:
+--------------------+
| Database |
+--------------------+
| oauth |
+-----------------+
| Tables_in_oauth |
+-----------------+
| user |
+-----------------+
+----+--------------------+-------+
| id | username | token |
+----+--------------------+-------+
| 1 | xxxx@yyyyyyyyy.com | |
+----+--------------------+-------+
我做错了什么? THX。
答案 0 :(得分:1)
您确定您的客户端ID或客户端密码是否正确?错误清楚地表明其中一个是错误的。