我正在构建一个应用程序,允许管理员通过身份验证访问其分析帐户以进行离线使用,并将刷新令牌存储在数据库中。
现在,当我尝试在前端使用API时,它会返回以下错误:
我需要一个类似 setRefreshToken 的功能,能够将先前在管理员身份验证过程中从数据库中获取的值输入其中进行刷新。
现在,当我尝试在前端使用API时,它会返回以下错误:
"Access Token Expired. There wan a general error : The OAuth 2.0 access token has expired, and a refresh token is not available. Refresh tokens are not returned for responses that were auto-approved."
以下是我的代码,目前会产生这个错误:
require_once "lib/google/Google_Client.php";
require_once "lib/google/contrib/Google_AnalyticsService.php";
$_analytics = new analytics();
$_googleClient = new Google_Client();
$_googleClient->setClientId($_analytics->gaClientId);
$_googleClient->setClientSecret($_analytics->gaClientSecret);
$_googleClient->setRedirectUri($_analytics->gaRedirectUri);
$_googleClient->setScopes($_analytics->gaScope);
$_googleClient->setAccessType($_analytics->gaAccessType);
// Returns last access token from the database (this works)
$_tokenArray['access_token'] = $_analytics->dbAccessToken($_agencyId);
$_googleClient->setAccessToken(json_encode($_tokenArray));
if($_googleClient->isAccessTokenExpired()) {
// Don't think this is required for Analytics API V3
//$_googleClient->refreshToken($_analytics->dbRefreshToken($_agencyId));
echo 'Access Token Expired'; // Debug
}
if (!$_googleClient->getAccessToken()) {
echo '<h2>Error - Admin has not setup analytics correct yet</h2>';
}
我需要一个类似 setRefreshToken 的功能,能够将先前在管理员身份验证过程中从数据库中获取的值输入其中进行刷新。
$_googleClient->refreshToken($NewAccessToken->refresh_token);
来强制获取新的令牌。然后只需比较旧令牌和新令牌是否有变化即可。 - Gareth Luckettauthenticate()
-- 为什么这个问题会得到这么多赞和勾选?!? - mpen