These samples show how to use the Google Cloud Firestore API to store and query data.
POST (collection) Document Id - randomly generated by firebase or by me USER (collection) Document Id - randomly generated by firebase userPost: String (this will be the document id in the post collection that I'm trying to get) firebase firebase-realtime-database google-cloud-firestore.
Open the Firebase Console and create a new project. (You can't use both Cloud Firestore and Cloud Datastore in the same project, which might affect apps using App Engine. Try using Cloud Firestore with a different project if this is the case).
In the Database section, click Try Firestore Beta.
Click Enable.
Authentication is typically done through Application Default Credentialswhich means you do not have to change the code to authenticate as long asyour environment has credentials. You have a few options for setting upauthentication:
When running locally, use the Google Cloud SDK
When running on App Engine or Compute Engine, credentials are alreadyset-up. However, you may need to configure your Compute Engine instancewith additional scopes.
You can create a Service Account key file. This file can be used toauthenticate to Google Cloud Platform services from any environment. To usethe file, set the GOOGLE_APPLICATION_CREDENTIALS
environment variable tothe path to the key file, for example:
Enable the Cloud Firestore API.
Install dependencies via Composer.Run php composer.phar install
(if composer is installed locally) or composer install
(if composer is installed globally).
Create a service account at theService account section in the Cloud Console
Download the json key file of the service account.
Set GOOGLE_APPLICATION_CREDENTIALS
environment variable pointing to that file.
To run the Cloud Firestore Samples:
This sample uses the Google Cloud Client Library for PHP.You can read the documentation for more details on API usage and use GitHubto browse the source and report issues.
If you get the following error, set the environment variable GCLOUD_PROJECT
to your project ID:
If you have not set a timezone you may get an error from php. This can be resolved by:
php -i grep 'Configuration File'
date.timezone = 'America/Los_Angeles'