【发布时间】:2024-05-21 05:15:01
【问题描述】:
我需要使用 jquery 获取 google 联系人。我已经成功地完全实施了。但问题是我无法获取该联系人的姓名。谷歌只是向我提供该用户的电子邮件地址。用户未提供其他信息。所以我想念一些东西。
在这里我附上完整的代码和响应。
这里是完整代码
<script type="text/javascript" src="https://apis.google.com/js/client.js"></script>
<script type="text/javascript">
var clientId = "google_clientId";
var apiKey = "google_api_key";
var scopes = 'https://www.google.com/m8/feeds/';
$(document).on("click", ".googleContactsButton", function (e) {
gapi.client.setApiKey(apiKey);
window.setTimeout(authorize);
});
function authorize() {
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: false}, handleAuthorization);
}
function handleAuthorization(authorizationResult) {
if (authorizationResult && !authorizationResult.error) {
$.get("https://www.google.com/m8/feeds/contacts/default/full?alt=json&access_token=" + authorizationResult.access_token + "&alt=json",
function (response) {
//process the response here
console.log(JSON.stringify(response));
});
}
}
</script>
这是 API 的响应
[
{
"id": {
"$t": "http://www.google.com/m8/feeds/contacts/ishan%40inheritx.com/base/87427988f9359bf"
},
"updated": {
"$t": "2016-07-21T08:09:55.053Z"
},
"category": [
{
"scheme": "http://schemas.google.com/g/2005#kind",
"term": "http://schemas.google.com/contact/2008#contact"
}
],
"title": {
"type": "text",
"$t": ""
},
"link": [
{
"rel": "http://schemas.google.com/contacts/2008/rel#edit-photo",
"type": "image/*",
"href": "https://www.google.com/m8/feeds/photos/media/ishan%40inheritx.com/87427988f9359bf/1B2M2Y8AsgTpgAmY7PhCfg"
},
{
"rel": "self",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/ishan%40inheritx.com/full/87427988f9359bf"
},
{
"rel": "edit",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/ishan%40inheritx.com/full/87427988f9359bf/1469088595053001"
}
],
"gd$email": [
{
"rel": "http://schemas.google.com/g/2005#other",
"address": "prakash@inheritx.com"
}
]
}
]
作为回应,我们没有找到像名字和姓氏这样的字段。任何帮助将不胜感激。
但如果我手动添加名称,那么它会在标题键中显示我。但如果该联系人姓名是从 google+ 同步的,那么它会显示为空白。
谢谢
【问题讨论】:
-
像我在回答中所做的那样,在 oauth 操场 Contactsv3 中进行快速试驾。
标签: google-api google-contacts-api google-shared-contacts google-profiles-api