我尝试获取身份验证代码并在函数中使用它来访问访问令牌。
但是我遇到了这个错误
InvalidArgumentException:'queryParams'类型错误;期望数组,得到了字符串
getAuthCode:
private function getWebAuth(){
# Include the Dropbox SDK libraries
$appKey = '<REDACTED>';
$appSecret = '<REDACTED>';
$appInfo = new dbx\AppInfo($appKey, $appSecret);
$clientIdentifier = "ExecutiveCoatings";
// Get the current domain protocol to use in the redirect uri
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
// genertate the correct redirect uri
$redirectUri = $protocol.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$redirectUri = str_replace("dropbox_start","dropbox_finish",$redirectUri);
$csrfTokenStore = new dbx\ArrayEntryStore($_SESSION, 'dropbox-auth-csrf-token');
$webAuth = new dbx\WebAuth($appInfo, $clientIdentifier, $redirectUri, $csrfTokenStore);
return $webAuth;
}
我可以在dropbox_start方法中使用getAuthCode函数:
public function dropbox_start()
{
$authorizeUrl = $this->getWebAuth()->start();
// send the user to Dropbox authentication page
header('Location: '.$authorizeUrl);
exit();
}
以及在dropbox_finish方法中,当我将WebAuth
设置为WebAuthNoRedirect
并在$ authCode部分中静态使用生成的代码,但是当我想动态获取$ authCode并进行设置和其他操作时它给了我错误:
public function dropbox_finish()
{
// get the accessToken from redirected uri
$authCode = $_GET['code'];
list($accessToken, $dropboxUserId) = $this->getWebAuth()->finish($authCode);
var_dump($accessToken);
session_destroy();
die();
}
怎么了?