【问题标题】:Google Contacts API 401 Authorization Required需要 Google 通讯录 API 401 授权
【发布时间】:2015-05-09 03:47:37
【问题描述】:

我在获得 oauth2 令牌后向 Google Contacts API 发出以下请求。

$.ajax({
         url: 'https://www.google.com/m8/feeds/contacts/XXXXXXXXX@gmail.com/full?access_token=' + authData.authorizationCode + '&alt=json',
         dataType: "jsonp",
         success:function(data) {
                    console.log((data));
                }
            });

这会产生以下 GET HTTP 请求:

https://www.google.com/m8/feeds/contacts/XXXXXXXXX@gmail.com/full?access_token=4/95N2f8xA1XXXXXXXXXXXXXXQC3BtuuMbk.Aug-7c4GLLMZXmXvfARQvtgU5IVtmgI&alt=json&callback=jQuery111XXXXX1426XXX03&_=1431142848004

但是 google 回复 状态码:401 需要授权

【问题讨论】:

    标签: google-api google-oauth google-contacts-api


    【解决方案1】:

    仅供参考,我使用的是授权码而不是访问令牌来请求联系方式。因此,为什么我会收到错误

    此处的图表说明了 oauth2 流程: https://developers.google.com/identity/protocols/OAuth2WebServer

    这是一个很好的资源,可以帮助您了解您的代码实际上应该做什么: https://developers.google.com/oauthplayground/

    以下是使用 googles oauth2 for api 的综合示例: http://www.9bitstudios.com/2013/05/using-oauth-2-0-for-google-apis/

    以下代码获取电子邮件联系人列表

    $.ajax({
                        url: 'https://www.google.com/m8/feeds/contacts/default/full?alt=json',
                        dataType: "jsonp",
                        data: {'access_token': authData.authorizationToken.access_token},
                        success:function(data) {
                            var entryOfEmails = data.feed.entry;
                            for (var i = 0; i < data.feed.entry.length; i++) {
                                    console.log(entryOfEmails[i].gd$email[0].address);
                                }
                        }
                     });  
    

    【讨论】:

    • 我遇到了同样的错误......你在哪里添加了访问令牌?能否请您提供代码 sn-p ...我正在尝试几个小时..
    猜你喜欢
    • 1970-01-01
    • 2014-01-29
    • 1970-01-01
    • 2019-12-05
    • 2011-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-04
    相关资源
    最近更新 更多