Google 联系人 API 401 需要授权
Google Contacts API 401 Authorization Required
我在获得 oauth2 令牌后向 Google 联系人 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 回复 状态 Code:401 需要授权
仅供参考,我使用的是授权码而不是访问令牌来请求联系方式。因此,为什么我收到错误
此处的图表说明了 oauth2 流程:
https://developers.google.com/identity/protocols/OAuth2WebServer
这是一个很好的资源,可以帮助您了解您的代码实际应该做什么:
https://developers.google.com/oauthplayground/
以下是针对 api 使用 googles oauth2 的综合示例:
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);
}
}
});
我在获得 oauth2 令牌后向 Google 联系人 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 回复 状态 Code:401 需要授权
仅供参考,我使用的是授权码而不是访问令牌来请求联系方式。因此,为什么我收到错误
此处的图表说明了 oauth2 流程: https://developers.google.com/identity/protocols/OAuth2WebServer
这是一个很好的资源,可以帮助您了解您的代码实际应该做什么: https://developers.google.com/oauthplayground/
以下是针对 api 使用 googles oauth2 的综合示例: 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);
}
}
});