【问题标题】:Google app engine imap invalid credentialsGoogle 应用引擎 imap 凭据无效
【发布时间】:2014-05-16 12:46:05
【问题描述】:

我正在尝试获取我的用户的电子邮件。我有一个服务帐户设置和一个来自客户端库的访问令牌。我将这些详细信息输入到此处https://developers.google.com/gmail/xoauth2_libraries 的 xoauth 库中。但我不断收到无效的凭据错误。一个帐户有效,它是管理员/模拟帐户,但其他帐户无效。这是一个 php 应用程序,有人可以帮忙。

$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);

【问题讨论】:

    标签: google-app-engine


    【解决方案1】:

    使用服务帐户和域范围的委派,您需要为每个用户创建一个访问令牌,也就是说,您需要一个接一个地模拟每个用户。

    管理员访问令牌不会让您访问其他用户的邮箱。

    【讨论】:

      猜你喜欢
      • 2011-12-26
      • 2014-10-15
      • 2018-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多