2

您好我已经通过 Javascript 方法(Javascript)实现了 Google Contacts V3 API。就像下面的片段:

//The google login url
https://www.googleapis.com/plus/v1/people/me
access_token='dsfjkasdkfjgasdf';


$.get("https://www.google.com/m8/feeds/contacts/default/full?access_token="+access_token+"&alt=json",{},function(xmldata) {
//console.log( xmldata.feed.entry );

var contacts =[];
$.each(xmldata.feed.entry,function(i,tag) {
    var contact_id=tag.id.$t;
    var name = tag.title.$t;
    var contact_emails = tag.gd$email; $.each(contact_emails,function(key,val){ social_email=val.address; });

    contacts.push({id:contact_id,name:name,email:social_email});

    console.log("id="+id+" name="+name+" email="+social_email+"\n");

    // store social contacts to db
});

},"json").fail(fail);

并成功响应:

 {
"id": {
    "$t": "http://www.google.com/m8/feeds/contacts/{email}/base/{contact_id}"
},
"updated": {
    "$t": "2013-01-10T05:16:03.705Z"
},
"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/{email}/{contact_id}/9sadsdkj90"
    },
    {
        "rel": "self",
        "type": "application/atom+xml",
        "href": "https://www.google.com/m8/feeds/contacts/{email}/full/{contact_id}"
    },
    {
        "rel": "edit",
        "type": "application/atom+xml",
        "href": "https://www.google.com/m8/feeds/contacts/{email}/full/{contact_id}/1357794963705ffdd1"
    }
],
"gd$email": [
    {
        "rel": "http://schemas.google.com/g/2005#other",
        "address": "ee@eefgj.com",
        "primary": "true"
    }
]
}

响应正在返回用户联系信息,但我还需要 Google 加号(即个人资料 ID)。

请建议我如何从联系人详细信息(姓名、电子邮件等)中获取 gid(Google+ id)?请帮助获取所有联系人的个人资料 ID...

4

1 回答 1

2

对于经过身份验证的用户,用户的 Google+ ID 与 OAuth 2.0 ID 相同,并且可以通过传入您的访问令牌从对 oauth2.tokeninfo 端点的 API 调用中检索到。

来自 tokeninfo 的响应将包含以下内容:

{
 "issued_to": "yourclientid.apps.googleusercontent.com",
 "audience": "yourclientid.apps.googleusercontent.com",
 "user_id": "{auth user's id}",
 "scope": ""
 "expires_in": 3584,
 "access_type": "online"
}

现在,您可能还想做的是检索与特定用户相关联的人的 Google+ id。这无法通过 Contacts API 实现,但可以通过列出用户在其 Google+ 圈子中对您的应用程序可见的人员来实现。

那里的 API 是plus.people.list

于 2014-02-13T02:19:54.090 回答