Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(samples): add people samples for get & create contacts #1543

Merged
merged 5 commits into from Jan 21, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}