【发布时间】:2013-10-22 15:44:43
【问题描述】:
我有一个在 Google App Engine 上运行的 PHP 应用程序,我想在其中使用 App Engine 的数据存储区。
我正在使用 google-api-php-client,并在 Google Cloud Console 上启用了 Google Cloud Datastore API,并注册了一个新应用,下载了私有证书。
对于身份验证,我使用以下代码(xxxx 具有实际值):
const SERVICE_ACCOUNT_NAME = 'xxxx@developer.gserviceaccount.com';
const KEY_FILE = 'secure/privatekey.p12';
$client = new Google_Client();
$key = file_get_contents ( KEY_FILE );
$client->setAssertionCredentials (
new Google_AssertionCredentials (
SERVICE_ACCOUNT_NAME,
array (
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/datastore'
),
$key
)
);
$service = new Google_DatastoreService ( $client );
$datasets = $service->datasets;
无论我在$datasets 中使用哪个操作,例如$datasets->lookup,我都会收到一个异常,指出该操作是未经授权的:
Uncaught exception 'Google_ServiceException' with message 'Error calling POST https://www.googleapis.com/datastore/v1beta1/datasets/<my-appengine-id>/lookup: (403) Unauthorized.'
可能出了什么问题?
【问题讨论】:
-
你的项目ID是什么? XXX的值是多少?
-
项目id是“flytour-intranet”,SERVICE_ACCOUNT_NAME是317403747968-mciqlisucn3o49ov1qfpk99rjievkld2@developer.gserviceaccount.com。
标签: php google-app-engine google-cloud-datastore