Skip to content

Commit

Permalink
docs(samples): add people samples for get & create contacts (#1543)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeRoddy authored and JustinBeckwith committed Jan 21, 2019
1 parent 2ad63f6 commit c62efb1
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions samples/people/contacts.js
@@ -0,0 +1,68 @@
// Copyright 2016, Google, Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const {google} = require('googleapis');
const sampleClient = require('../sampleclient');

const people = google.people({
version: 'v1',
auth: sampleClient.oAuth2Client,
});

async function runSample() {
// List all user's contact groups
// https://developers.google.com/people/api/rest/v1/contactGroups
const {data: groups} = await people.people.get({
resourceName: 'contactGroups',
});
console.log('Contact Groups:\n', groups);

// List all user connections / contacts
// https://developers.google.com/people/api/rest/v1/people.connections
const {
data: {connections},
} = await people.people.connections.list({
personFields: ['names', 'emailAddresses'],
resourceName: 'people/me',
pageSize: 10,
});
console.log("\n\nUser's Connections:\n");
connections.forEach(c => console.log(c));

// Create a new contact
// https://developers.google.com/people/api/rest/v1/people/createContact
const {data: newContact} = await people.people.createContact({
requestBody: {
emailAddresses: [{value: 'john@doe.com'}],
names: [
{
displayName: 'John Doe',
familyName: 'Doe',
givenName: 'John',
},
],
},
});
console.log('\n\nCreated Contact:', newContact);
}

const scopes = ['https://www.googleapis.com/auth/contacts'];

if (module === require.main) {
sampleClient
.authenticate(scopes)
.then(runSample)
.catch(console.error);
}

0 comments on commit c62efb1

Please sign in to comment.