Skip to content

Commit 946aa96

Browse files
fix: do not require projectId for samples (#147)
1 parent f2ebd4a commit 946aa96

2 files changed

Lines changed: 7 additions & 30 deletions

File tree

packages/google-cloud-bigquery-datatransfer/README.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,12 @@ Google APIs Client Libraries, in [Client Libraries Explained][explained].
6161
### Using the client library
6262

6363
```javascript
64-
65-
if (
66-
!process.env.GCLOUD_PROJECT ||
67-
!process.env.GOOGLE_APPLICATION_CREDENTIALS
68-
) {
69-
throw new Error(
70-
'Usage: GCLOUD_PROJECT=<project_id> GOOGLE_APPLICATION_CREDENTIALS=<path to key json file> node #{$0}'
71-
);
72-
}
73-
7464
const bigqueryDataTransfer = require('@google-cloud/bigquery-data-transfer');
7565

7666
const client = new bigqueryDataTransfer.v1.DataTransferServiceClient({
7767
// optional auth parameters.
7868
});
79-
const projectId = process.env.GCLOUD_PROJECT;
69+
const projectId = await client.getProjectId();
8070

8171
// Iterate over all elements.
8272
const formattedParent = client.locationPath(projectId, 'us-central1');

packages/google-cloud-bigquery-datatransfer/samples/quickstart.js

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,12 @@
1313
// limitations under the License.
1414

1515
'use strict';
16-
async function main() {
17-
// [START bigquerydatatransfer_quickstart]
18-
19-
if (
20-
!process.env.GCLOUD_PROJECT ||
21-
!process.env.GOOGLE_APPLICATION_CREDENTIALS
22-
) {
23-
throw new Error(
24-
'Usage: GCLOUD_PROJECT=<project_id> GOOGLE_APPLICATION_CREDENTIALS=<path to key json file> node #{$0}'
25-
);
26-
}
2716

17+
// [START bigquerydatatransfer_quickstart]
18+
async function quickstart() {
2819
const bigqueryDataTransfer = require('@google-cloud/bigquery-data-transfer');
29-
30-
const client = new bigqueryDataTransfer.v1.DataTransferServiceClient({
31-
// optional auth parameters.
32-
});
33-
const projectId = process.env.GCLOUD_PROJECT;
20+
const client = new bigqueryDataTransfer.v1.DataTransferServiceClient();
21+
const projectId = await client.getProjectId();
3422

3523
// Iterate over all elements.
3624
const formattedParent = client.projectPath(projectId, 'us-central1');
@@ -59,7 +47,6 @@ async function main() {
5947
.on('data', element => {
6048
console.log(` ${element.name}`);
6149
});
62-
// [END bigquerydatatransfer_quickstart]
6350
}
64-
65-
main().catch(console.error);
51+
quickstart().catch(console.error);
52+
// [END bigquerydatatransfer_quickstart]

0 commit comments

Comments
 (0)