Как создать контакт через людей API в JavaScript? - PullRequest
0 голосов
/ 05 июля 2018

Как передать родительский элемент (т. Е. Параметр) и тело запроса, чтобы он добавлял контакт в контакты Google через People API.

function CreateContact() {
    gapi.client.people.people.createContact({
        parent: 'people/me',
        requestBody: {
            locales: [{value: 'en'}],
            genders: [{value: 'female'}]
        }
    })
}

1 Ответ

0 голосов
/ 11 июля 2018
 // 2. Initialize the JavaScript client library.
    gapi.client.init({
        'apiKey': 'Your API key',
        // clientId and scope are optional if auth is not required.
        'clientId': 'Your CLIENT ID',
        'scope': 'https://www.googleapis.com/auth/contacts',
    }).then(function () {
        // 3. Initialize and make the API request.
        return gapi.client.request({
            'method': "POST",
            'path': 'https://people.googleapis.com/v1/people:createContact',
            'datatype': 'jsonp',
            'parent': "Name the parent",
            'body': {
                "names": [
                    {
                        "givenName": "Name to be given"
                    }
                ],
                "emailAddresses": [
                    {
                        "value": "Email_Add to be given"
                    }
                ],
                "phoneNumbers": [
                    {
                        "value": "phone number to be given"
                    }
                ]
            }
        })

    }).then(function (response) {
        console.log(response.result);
        document.getElementById("test").innerHTML = "Create New contact Please Check into google contacts";

    }, function (reason) {
        console.log('Error: ' + reason.result.error.message);
    });
};

После инициализации клиентской библиотеки Javascript ее необходимо загрузить с помощью:

gapi.load('client', function_name_of_intitiation_method)
...