Search code examples
phpgoogle-app-enginegoogle-cloud-datastore

Class not found in Google Cloud app


I am getting the following error:

Fatal error: Class 'Google\Cloud\Datastore\DatastoreClient' not found in /base/data/home/apps/e~brookes-room-usage/1.3998538263957262‌​38/record-usage.php on line 84

so presumably I have failed to point my app correctly to that class.

I have enabled the Datastore API on the cloud console.

I have tried to find documentation relating to how to set up a PHP connection to the Datastore API.

I tried to create a settings.yml file using the instructions here but I didn't know what my client ID or my client secret were.

# 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)

What do I need to get my PHP app on Google Cloud to recognise Google\Cloud\Datastore\DatastoreClient and connect to the Datastore API so that I can retrieve and post data?


Solution

  • So it turns out that you can only run PHP with Datastore on a Google Cloud app on your local device, not on Google Appengine, unless you use a third-party library.

    Which is why I am now writing my app in Python instead.

    (Update: this may no longer be the case. This answer was written in 2017.)