【问题标题】:Class not found in Google Cloud app在 Google Cloud 应用中找不到课程
【发布时间】:2017-08-06 10:17:25
【问题描述】:

我收到以下错误:

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

所以大概我没有正确地将我的应用程序指向那个类。

我已在云控制台上启用了 Datastore 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 并连接到 Datastore API 以便检索和发布数据?

【问题讨论】:

  • 好的,使用这些说明正确编写了 settings.yml 文件。 cloud.google.com/php/getting-started/authenticate-users我还需要什么吗?
  • 我需要安装 Composer 吗?
  • 所以事实证明,除非您使用第三方库,否则您只能在本地设备上的 Google Cloud 应用程序上运行 PHP 和 Datastore,而不能在 Google Appengine 上运行。

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


【解决方案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 我已经在使用它并且对我来说工作正常。

【讨论】:

    【解决方案2】:

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

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

    更新:可能不再是这种情况了。这个答案写于 2017 年。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-18
      • 1970-01-01
      • 2017-01-20
      • 1970-01-01
      • 2014-09-29
      • 2016-09-12
      • 2020-01-16
      • 2016-05-12
      相关资源
      最近更新 更多