【发布时间】: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