@@ -7,35 +7,80 @@ This simple command-line application demonstrates how to invoke
7
7
8
8
[ pubsub ] : https://cloud.google.com/pubsub/docs/quickstart-client-libraries
9
9
10
- ## Build and Run
11
- 1 . ** Enable APIs** - [ Enable the Pub\Sub API] ( https://console.cloud.google.com/flows/enableapi?apiid=pubsub )
12
- and create a new project or select an existing project.
13
- 2 . ** Download The Credentials** - Click "Go to credentials" after enabling the APIs. Click "New Credentials"
14
- and select "Service Account Key". Create a new service account, use the JSON key type, and
15
- select "Create". Once downloaded, set the environment variable ` GOOGLE_APPLICATION_CREDENTIALS `
16
- to the path of the JSON key that was downloaded.
17
- 3 . ** Clone the repo** and cd into this directory
18
-
19
- ``` sh
20
- $ git clone https://github.com/GoogleCloudPlatform/php-docs-samples
21
- $ cd php-docs-samples/pubsub/api
22
- ```
23
- 4 . ** Install dependencies** via [ Composer] ( http://getcomposer.org/doc/00-intro.md ) .
10
+ ## Setup
11
+
12
+ ### Authentication
13
+
14
+ Authentication is typically done through [ Application Default Credentials] [ adc ]
15
+ which means you do not have to change the code to authenticate as long as
16
+ your environment has credentials. You have a few options for setting up
17
+ authentication:
18
+
19
+ 1 . When running locally, use the [ Google Cloud SDK] [ google-cloud-sdk ]
20
+
21
+ gcloud auth application-default login
22
+
23
+ 1 . When running on App Engine or Compute Engine, credentials are already
24
+ set-up. However, you may need to configure your Compute Engine instance
25
+ with [ additional scopes] [ additional_scopes ] .
26
+
27
+ 1 . You can create a [ Service Account key file] [ service_account_key_file ] . This file can be used to
28
+ authenticate to Google Cloud Platform services from any environment. To use
29
+ the file, set the `` GOOGLE_APPLICATION_CREDENTIALS `` environment variable to
30
+ the path to the key file, for example:
31
+
32
+ export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json
33
+
34
+ [ adc ] : https://cloud.google.com/docs/authentication#getting_credentials_for_server-centric_flow
35
+ [ additional_scopes ] : https://cloud.google.com/compute/docs/authentication#using
36
+ [ service_account_key_file ] : https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount
37
+
38
+ ## Install Dependencies
39
+
40
+ 1 . Ensure the [ gRPC PHP Extension] [ php_grpc ] is installed and enabled on your machine.
41
+ 1 . [ Enable the Cloud Pub/Sub API] ( https://console.cloud.google.com/flows/enableapi?apiid=pubsub.googleapis.com ) .
42
+
43
+ 1 . ** Install dependencies** via [ Composer] ( http://getcomposer.org/doc/00-intro.md ) .
24
44
Run ` php composer.phar install ` (if composer is installed locally) or ` composer install `
25
45
(if composer is installed globally).
26
- 5 . Run ` php pubsub.php ` . The following commands are available:
27
46
28
- ``` sh
29
- iam Manage IAM for Pub\S ub
30
- subscription Manage subscriptions for Pub\S ub
31
- topic Manage topics for Pub\S ub
47
+ 1 . Create a service account at the
48
+ [ Service account section in the Cloud Console] ( https://console.cloud.google.com/iam-admin/serviceaccounts/ )
49
+
50
+ 1 . Download the json key file of the service account.
51
+
52
+ 1 . Set ` GOOGLE_APPLICATION_CREDENTIALS ` environment variable pointing to that file.
53
+
54
+ ## Samples
55
+
56
+ To run the Pub/Sub Samples, run any of the files in ` src/ ` on the CLI:
57
+
58
+ ```
59
+ $ php src/create-topic.php
60
+
61
+ Usage: create_topic.php $projectId $topicName
62
+
63
+ @param string $projectId The Google project ID.
64
+ @param string $topicName The Pub/Sub topic name.
32
65
```
33
- 6 . Run ` php pubsub.php COMMAND --help ` to print information about the usage of each command.
34
66
35
- ## Contributing changes
67
+ ## Troubleshooting
68
+
69
+ If you get the following error, set the environment variable ` GCLOUD_PROJECT ` to your project ID:
70
+
71
+ ```
72
+ [Google\Cloud\Core\Exception\GoogleException]
73
+ No project ID was provided, and we were unable to detect a default project ID.
74
+ ```
36
75
37
- * See [ CONTRIBUTING.md ] ( ../../CONTRIBUTING.md )
76
+ ## The client library
38
77
39
- ## Licensing
78
+ This sample uses the [ Google Cloud Client Library for PHP] [ google-cloud-php ] .
79
+ You can read the documentation for more details on API usage and use GitHub
80
+ to [ browse the source] [ google-cloud-php-source ] and [ report issues] [ google-cloud-php-issues ] .
40
81
41
- * See [ LICENSE] ( ../../LICENSE )
82
+ [ php_grpc ] : http://cloud.google.com/php/grpc
83
+ [ google-cloud-php ] : https://googlecloudplatform.github.io/google-cloud-php
84
+ [ google-cloud-php-source ] : https://github.com/GoogleCloudPlatform/google-cloud-php
85
+ [ google-cloud-php-issues ] : https://github.com/GoogleCloudPlatform/google-cloud-php/issues
86
+ [ google-cloud-sdk ] : https://cloud.google.com/sdk/
0 commit comments