如何通过 javascript 中的人 API 创建联系人?
How to create a contact through people API in javascript?
如何传递父级(即参数)和请求正文,以便通过人员 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)
如何传递父级(即参数)和请求正文,以便通过人员 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)