@@ -16,38 +16,80 @@ This simple command-line application demonstrates how to invoke
1616
1717* See [ LICENSE] ( ../../LICENSE )
1818
19- ## Build and Run
20- 1 . ** Enable APIs** - [ Enable the Storage API] ( https://console.cloud.google.com/flows/enableapi?apiid=storage_api )
21- and create a new project or select an existing project.
22- 2 . ** Download The Credentials** - Click "Go to credentials" after enabling the APIs. Click "New Credentials"
23- and select "Service Account Key". Create a new service account, use the JSON key type, and
24- select "Create". Once downloaded, set the environment variable ` GOOGLE_APPLICATION_CREDENTIALS `
25- to the path of the JSON key that was downloaded.
26- 3 . ** Clone the repo** and cd into this directory
27-
28- ``` sh
29- $ git clone https://github.com/GoogleCloudPlatform/php-docs-samples
30- $ cd php-docs-samples/storage
31- ```
32- 4. ** Install dependencies** via [Composer](http://getcomposer.org/doc/00-intro.md).
19+ ### Authentication
20+
21+ Authentication is typically done through [ Application Default Credentials] [ adc ]
22+ which means you do not have to change the code to authenticate as long as
23+ your environment has credentials. You have a few options for setting up
24+ authentication:
25+
26+ 1 . When running locally, use the [ Google Cloud SDK] [ google-cloud-sdk ]
27+
28+ gcloud auth application-default login
29+
30+ 1 . When running on App Engine or Compute Engine, credentials are already
31+ set-up. However, you may need to configure your Compute Engine instance
32+ with [ additional scopes] [ additional_scopes ] .
33+
34+ 1 . You can create a [ Service Account key file] [ service_account_key_file ] . This file can be used to
35+ authenticate to Google Cloud Platform services from any environment. To use
36+ the file, set the `` GOOGLE_APPLICATION_CREDENTIALS `` environment variable to
37+ the path to the key file, for example:
38+
39+ export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json
40+
41+ [ adc ] : https://cloud.google.com/docs/authentication#getting_credentials_for_server-centric_flow
42+ [ additional_scopes ] : https://cloud.google.com/compute/docs/authentication#using
43+ [ service_account_key_file ] : https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount
44+
45+ ## Install Dependencies
46+
47+ 1 . [ Enable the Cloud Storage API] ( https://console.cloud.google.com/flows/enableapi?apiid=storage.googleapis.com ) .
48+
49+ 1 . ** Install dependencies** via [ Composer] ( http://getcomposer.org/doc/00-intro.md ) .
3350 Run ` php composer.phar install ` (if composer is installed locally) or ` composer install `
3451 (if composer is installed globally).
35- 5. Run ` php storage.php` to see a list of commands:
36-
37- ` ` ` sh
38- bucket-lock Manage Cloud Storage retention policies and holds
39- object-acl Manage the ACL for Cloud Storage objects
40- objects Manage Cloud Storage objects
41- requester-pays Manage Cloud Storage requester pays buckets and objects
42- uniform-bucket-level-access Manage Cloud Storage uniform bucket-level access buckets
43- get-object-v2-signed-url Generate a v2 signed URL for downloading an object.
44- get-object-v4-signed-url Generate a v4 signed URL for downloading an object.
45- get-object-v4-upload-signed-url Generate a v4 signed URL for uploading an object.
46- hmac-sa-manage Manage HMAC Service Account keys.
47- hmac-sa-list List HMAC Service Account keys.
48- hmac-sa-create Create an HMAC Service Account key.
49- ` ` `
50- 6. Run ` php storage.php COMMAND --help` to print information about the usage of each command.
52+
53+ 1 . Create a service account at the
54+ [ Service account section in the Cloud Console] ( https://console.cloud.google.com/iam-admin/serviceaccounts/ )
55+
56+ 1 . Download the json key file of the service account.
57+
58+ 1 . Set ` GOOGLE_APPLICATION_CREDENTIALS ` environment variable pointing to that file.
59+
60+ ## Samples
61+
62+ To run the Storage Samples, run any of the files in ` src/ ` on the CLI:
63+
64+ ```
65+ $ php src/create_bucket.php
66+
67+ Usage: create_bucket.php $bucketName
68+
69+ @param string $projectId The Project ID
70+ @param string $bucketName The Storage bucket name
71+ ```
72+
73+ ## Troubleshooting
74+
75+ If you get the following error, set the environment variable ` GCLOUD_PROJECT ` to your project ID:
76+
77+ ```
78+ [Google\Cloud\Core\Exception\GoogleException]
79+ No project ID was provided, and we were unable to detect a default project ID.
80+ ```
81+
82+ ## The client library
83+
84+ This sample uses the [ Google Cloud Client Library for PHP] [ google-cloud-php ] .
85+ You can read the documentation for more details on API usage and use GitHub
86+ to [ browse the source] [ google-cloud-php-source ] and [ report issues] [ google-cloud-php-issues ] .
87+
88+ [ google-cloud-php ] : https://googlecloudplatform.github.io/google-cloud-php
89+ [ google-cloud-php-source ] : https://github.com/GoogleCloudPlatform/google-cloud-php
90+ [ google-cloud-php-issues ] : https://github.com/GoogleCloudPlatform/google-cloud-php/issues
91+ [ google-cloud-sdk ] : https://cloud.google.com/sdk/
92+
5193
5294## Contributing changes
5395
0 commit comments