0
我正在尝试获取我的用户的电子邮件。我有一个服务帐户设置和来自客户端库的访问令牌。我将这些详细信息输入到此处找到的xoauth库https://developers.google.com/gmail/xoauth2_libraries。但我不断收到无效的凭据错误。一个帐户有效,其管理员/模拟帐户但没有其他人工作。这是一个PHP应用程序可以有人请帮助。Google应用引擎imap无效凭据
$client = new Google_Client();
$client -> setApplicationName("TTS Dashboard");
$client -> setClientId(CLIENTID);
$client -> setClientSecret(CLIENTSECRET);
$oauth2 = new Google_Service_Oauth2($client);
$directoryService = new Google_Service_Directory($client);
$driveService = new Google_Service_Drive($client);
$calendarService = new Google_Service_Calendar($client);
if (isset($_SESSION['service_token'])) {
$client -> setAccessToken($_SESSION['service_token']);
}
$path = 'http://' . $_SERVER['HTTP_HOST'] . "/static/" . KEYFILEPATH;
$key = file_get_contents($path);
$cred = new Google_Auth_AssertionCredentials(SERVICEACCOUNTEMAIL, $scopes, $key);
$cred -> sub = $impersonatedEmailAddress;
$client -> setAssertionCredentials($cred);
$client -> getAuth() -> refreshTokenWithAssertion($cred);
if ($client -> getAuth() -> isAccessTokenExpired()) {
$client -> getAuth() -> refreshTokenWithAssertion($cred);
}
$_SESSION['service_token'] = $client -> getAccessToken();
function GetAccessTokenString() {
$accessToken = $_SESSION['service_token'];
$token = json_decode($accessToken, true);
$tokenString = $token['access_token'];
return $tokenString;
}
// Get access token string value
$tokenString = GetAccessTokenString();
tryImapLogin($studentEmail, $tokenString);