【问题标题】:GAE - Error refreshing OAuth2 tokenGAE - 刷新 OAuth2 令牌时出错
【发布时间】:2014-01-27 12:36:00
【问题描述】:

我有一个在 GAE 上运行的 PHP 应用程序。它使用 Google PHP 库 (v0.6.7) 连接到 Cloud Datastore。此连接在大多数情况下都可以正常工作,但偶尔会出现以下错误,表明尝试刷新 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 文件来自动连接到 Datastore 服务。

 $account = 'xxxxxxx@developer.gserviceaccount.com';

 $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),我们正计划迁移到这个版本。但是,在执行此操作之前,了解可能导致此问题的原因将非常有用。

【问题讨论】:

    标签: google-app-engine google-cloud-datastore google-api-php-client


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-28
      • 1970-01-01
      • 1970-01-01
      • 2017-04-20
      • 1970-01-01
      • 1970-01-01
      • 2017-12-13
      • 2012-07-21
      相关资源
      最近更新 更多