我正在尝试使用Dropbox PHP设置一个基本的身份验证示例,但我失败了。当我启动我的index.php时,我被重定向到Dropbox登录。然后,一旦我登录,我重定向回dropbox_finish.php
和我有state
和code
如:使用PHP的Dropbox SDK
?state=bKwCAATDb7A5JLHmCj8wgA%3D%3D&code=YQb8c261HlAAAAAAAAAAXAK1OOk6DqK-RtqnJ_SG0F0
比我得到这个错误:
[Mon May 25 00:27:39.074399 2015] [:error] [pid 5459] [client 127.0.0.1:44489] PHP Fatal error: Uncaught exception 'Dropbox\Exception_BadRequest' with message 'HTTP status 400\n{"error_description": "Invalid client_id or client_secret", "error": "invalid_client"}' in /var/www/php/oauth/vendor/dropbox/dropbox-sdk/lib/Dropbox/RequestUtil.php:250\nStack trace:\n#0 /var/www/php/oauth/vendor/dropbox/dropbox-sdk/lib/Dropbox/WebAuthBase.php(39): Dropbox\RequestUtil::unexpectedStatus(Object(Dropbox\HttpResponse))\n#1 /var/www/php/oauth/vendor/dropbox/dropbox-sdk/lib/Dropbox/WebAuth.php(270): Dropbox\WebAuthBase->_finish('YQb8c261HlAAAAA...', ' https://oauth.d ...')\n#2 /var/www/php/oauth/web/dropbox_finish.php(4): Dropbox\WebAuth->finish(Array)\n#3 {main}\n thrown in /var/www/php/oauth/vendor/dropbox/dropbox-sdk/lib/Dropbox/RequestUtil.php on line 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 | [email protected] | |
+----+--------------------+-------+
我在做什么错? thx。
您确定您的客户端ID或客户端密码正确吗? –
你是对的,秘密是不正确的,现在我得到这个错误:'[Mon May 25 02:07:49.303137 2015] [:error] [pid 5457] [client 127.0.0.1:45996] PHP Warning :PDOStatement :: execute():SQLSTATE [HY093]:无效的参数编号:绑定变量的数量与第7行上的/var/www/php/oauth/web/dropbox_finish.php中的标记数量不匹配 – wti
请接受答案是正确的。这是一个不同的问题。 –