1

我有一个在GAE上运行的PHP应用程序。它使用Google PHP库(v0.6.7)连接到云数据存储。这种连接在大多数情况下都能正常工作,但偶尔会出现以下错误,指示尝试刷新OAuth2令牌时发生错误。GAE - 刷新OAuth2令牌时出错

Error refreshing the OAuth2 token, message: '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Google Accounts</title><meta http-equiv="content-type" content="text/html; charset=utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge" /><meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=0" /> 

该消息还包括在末端执行以下操作:

You are not authorized to perform this request 

我附下面的代码用于此连接。正如您所看到的,我正在使用一个P12文件来自动连接到数据存储服务。

$account = '[email protected]'; 

$key = file_get_contents(dirname(__FILE__).'/../google-api-php-client/privatekey.p12'); 
    $client = new Google_Client(); 
    $client->setApplicationName($this->appId); 

    $client->setAssertionCredentials(
      new Google_AssertionCredentials(
        $account, 
        array('https://www.googleapis.com/auth/userinfo.email', 
          'https://www.googleapis.com/auth/datastore'), 
        $key) 
    ); 


    $datastore = new Google_DatastoreService($client); 

的事情是,我不知道这是否是一个GAE的问题还是我可以做一些事情在我的代码来解决这个问题,或者至少尽量减少返回该错误的请求数。

我看到有一个新的图书馆版本(1.0.1-beta),我们计划迁移到这个版本。然而,在做这件事之前,对这个问题的原因有什么想法是非常有用的。

回答

0

我回答自己,以防万一有人发现它有用。

执行一些测试后,我意识到连接后返回的令牌没有正确存储。结果,系统试图在每个请求中刷新令牌。显然,在给定数量的请求之后,Google只是拒绝为该用户刷新令牌的任何新尝试,导致我在上面显示的错误。