|
| 1 | +/** |
| 2 | + * Copyright 2018, Google, LLC. |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + * See the License for the specific language governing permissions and |
| 13 | + * limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +'use strict'; |
| 17 | + |
| 18 | +// [START quickstart] |
| 19 | + |
| 20 | +// Imports the Google APIs client library |
| 21 | +const {google} = require('googleapis'); |
| 22 | + |
| 23 | +// Acquires credentials |
| 24 | +google.auth.getApplicationDefault((err, authClient) => { |
| 25 | + if (err) { |
| 26 | + console.error('Failed to acquire credentials'); |
| 27 | + console.error(err); |
| 28 | + return; |
| 29 | + } |
| 30 | + |
| 31 | + if (authClient.createScopedRequired && authClient.createScopedRequired()) { |
| 32 | + authClient = authClient.createScoped([ |
| 33 | + 'https://www.googleapis.com/auth/jobs' |
| 34 | + ]); |
| 35 | + } |
| 36 | + |
| 37 | + // Instantiates an authorized client |
| 38 | + const jobs = google.jobs({ |
| 39 | + version: 'v2', |
| 40 | + auth: authClient |
| 41 | + }); |
| 42 | + |
| 43 | + // Lists companies |
| 44 | + jobs.companies.list((err, result) => { |
| 45 | + if (err) { |
| 46 | + console.error(err); |
| 47 | + return; |
| 48 | + } |
| 49 | + |
| 50 | + console.log(`Request ID: ${result.data.metadata.requestId}`); |
| 51 | + |
| 52 | + const companies = result.data.companies || []; |
| 53 | + |
| 54 | + if (companies.length) { |
| 55 | + console.log('Companies:'); |
| 56 | + companies.forEach((company) => console.log(company.name)); |
| 57 | + } else { |
| 58 | + console.log(`No companies found.`); |
| 59 | + } |
| 60 | + }); |
| 61 | +}); |
| 62 | +// [END quickstart] |
0 commit comments