Google Cloud应用中找不到的类

时间:2017-03-15 15:14:56

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

我收到以下错误:

  

致命错误:在第84行的/base/data/home/apps/e~brookes-room-usage/1.3998538263957262 38 / record-usage.php中找不到“Google \ Cloud \ Datastore \ DatastoreClient”类< / p>

所以我可能无法正确地将我的应用指向该课程。

我已在云控制台上启用了数据存储区API。

我试图找到有关如何设置与Datastore API的PHP连接的文档。

我尝试create a settings.yml file using the instructions here但我不知道我的客户ID或我的客户秘密是什么。

# Google credentials and configuration
google_client_id:      YOUR_CLIENT_ID
google_client_secret:  YOUR_CLIENT_SECRET
google_project_id:     YOUR_PROJECT_ID

# options are "cloudsql", "mongodb", or "datastore"
bookshelf_backend: datastore

source on Github

我需要在Google Cloud上获取我的PHP应用以识别Google\Cloud\Datastore\DatastoreClient并连接到数据存储区API,以便我可以检索和发布数据吗?

2 个答案:

答案 0 :(得分:1)

我想你忘了加入google/cloud-datastore库。通过composer安装如下。

$ composer require google/cloud-datastore

你可以使用如下。

<?php 
require 'vendor/autoload.php';

use Google\Cloud\Datastore\DatastoreClient;

$datastore = new DatastoreClient([
    'projectId' => 'my_project'
]);

// Create an entity
$bob = $datastore->entity('Person');
$bob['firstName'] = 'Bob';
$bob['email'] = 'bob@example.com';
$datastore->insert($bob);

// Update the entity
$bob['email'] = 'bobV2@example.com';
$datastore->update($bob);

// If you know the ID of the entity, you can look it up
$key = $datastore->key('Person', '12345328897844');
$entity = $datastore->lookup($key);

更多详情:https://github.com/GoogleCloudPlatform/google-cloud-php#google-cloud-datastore-ga 我已经在使用它并且对我来说工作正常。

答案 1 :(得分:0)

事实证明,除非您使用第三方库,否则您只能在本地设备上的Google Cloud应用上运行PHP,而不能在Google Appengine上运行。

这就是我现在用Python编写应用程序的原因。