如何在javascript中通过人员API创建联系人?



如何传递父项(即参数(和请求正文,以便它通过People API将联系人添加到Google联系人中。

function CreateContact() {
gapi.client.people.people.createContact({
parent: 'people/me',
requestBody: {
locales: [{value: 'en'}],
genders: [{value: 'female'}]
}
})
}
// 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)

最新更新