Skip to content

Commit a2eeb43

Browse files
committed
refactors for Application Default Credentials in bigquery sample
1 parent 059bfcd commit a2eeb43

File tree

5 files changed

+562
-80
lines changed

5 files changed

+562
-80
lines changed

bigquery/api/README.md

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,40 @@
55
This simple command-line application demonstrates how to invoke Google BigQuery from PHP.
66

77
## Build and Run
8-
1. In the [Google Developers Console](https://console.developers.google.com/),
9-
create a new project or choose an existing project.
10-
2. In the [Google Developers Console](https://console.developers.google.com/),
11-
click **APIs & auth**, then click APIs. Wait for a list of APIs to
12-
appear, then click BigQuery. If BigQuery is not already enabled,
13-
click the Enable API button.
14-
3. In the [Google Developers Console](https://console.developers.google.com/),
15-
under **APIs & auth**, click Credentials. Click the button to "Generate
16-
a new JSON key." Set the environment variable
17-
`GOOGLE_APPLICATION_CREDENTIALS` to the path of the JSON key that was
18-
downloaded.
19-
3. Clone this repo with
8+
1. **Enable APIs** - [Enable the BigQuery API](https://console.cloud.google.com/flows/enableapi?apiid=bigquery)
9+
and create a new project or select an existing project.
10+
2. **Download The Credentials** - Click "Go to credentials" after enabling the APIs. Click "New Credentials"
11+
and select "Service Account Key". Create a new service account, use the JSON key type, and
12+
select "Create". Once downloaded, set the environment variable `GOOGLE_APPLICATION_CREDENTIALS`
13+
to the path of the JSON key that was downloaded.
14+
3. **Clone the repo** and cd into this directory
2015

2116
```sh
22-
git clone https://github.com/GoogleCloudPlatform/php-docs-samples
17+
$ git clone https://github.com/GoogleCloudPlatform/php-docs-samples
18+
$ cd php-docs-samples/bigquery/api
19+
```
20+
4. **Install dependencies** via [Composer](http://getcomposer.org/doc/00-intro.md).
21+
Run `php composer.phar install` (if composer is installed locally) or `composer install`
22+
(if composer is installed globally).
23+
5. Run `php main.php YOUR_PROJECT_NAME` where YOUR_PROJECT_NAME is the
24+
project associated with the credentials from **step 2**.
25+
26+
```sh
27+
$ php main.php my-project-name
28+
29+
Query Results:
30+
------------
31+
hamlet 5318
32+
kinghenryv 5104
33+
cymbeline 4875
34+
troilusandcressida 4795
35+
kinglear 4784
36+
kingrichardiii 4713
37+
2kinghenryvi 4683
38+
coriolanus 4653
39+
2kinghenryiv 4605
40+
antonyandcleopatra 4582
2341
```
24-
4. cd into the bigquery directory.
25-
5. Download [Composer](http://getcomposer.org/doc/00-intro.md) or update `composer self-update`.
26-
6. Run `php composer.phar install`.
27-
7. Run `php main.php`.
2842

2943
## Contributing changes
3044

bigquery/api/composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"require": {
3-
"google/apiclient": "1.1.5"
4-
}
2+
"require": {
3+
"google/apiclient": "~2.0@RC"
4+
}
55
}

0 commit comments

Comments
 (0)