0

I have a PHP application running at Google App Engine and I want to use the App Engine's datastore in it.

I am using the google-api-php-client, and at the Google Cloud Console I've enabled the Google Cloud Datastore API, and registered a new app, downloading the private certificate.

For the authentication, I'm using the following code (xxxx has the real values):

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;

Whichever operation I use in $datasets, like $datasets->lookup, I receive an exception stating that the operation is Unauthorized:

Uncaught exception 'Google_ServiceException' with message 'Error calling POST https://www.googleapis.com/datastore/v1beta1/datasets/<my-appengine-id>/lookup: (403) Unauthorized.'

What might be wrong?

4

1 回答 1

2

我相信您遇到了以下限制:服务帐户授权不适用于受域限制的 App Engine 应用程序

因此,您可以对该问题发表评论以将您的应用程序列入白名单,请记住,它可以允许域外的帐户使用 OAuth 对您的应用程序进行身份验证,具体取决于您的应用程序的构建方式。

于 2013-10-22T19:11:23.140 回答