1

我想使用 google contacts api v3 来获取帐户的所有联系人,但是当我使用 jquery ajax 请求时,每个请求都会发生此错误:

jQuery.ajax({
url: "https://www.google.com/m8/feeds/contacts/default/full",
headers: {
    'Authorization': "Bearer dff55.Cj_CA27T4Fsdfsdfsdfsdfds",
    'Content-Type': 'application/json'
},
method: 'GET',
dataType: 'jsonp',
jsonp: false,
success: function (data) {
    console.log('succes: ' + data);
},
error: function (data) {
    console.log('error');
    console.log(data);
}
});

我使用这个文档:https ://developers.google.com/google-apps/contacts/v3/

但我认为有问题,https://www.google.com/m8/feeds/contacts/default/full因为任何请求的结果都是一回事!readyState: 4, status: 404, statusText: "error"

4

1 回答 1

0

在搜索更多并向其他人询问我的问题后,将alt=jsonaccesstoken 添加到 url 并禁用jsonp: falsecache: true因为请求需要 jsonp 。

工作代码是这样的:

jQuery.ajax({
url: "https://www.google.com/m8/feeds/contacts/default/full?alt=json&access_token=" + hashdic["access_token"] + "&max-results=10&v=3.0",
headers: {
    'Authorization': "Bearer XXXXX",
    'Content-Type': 'application/json'
},
method: 'GET',
dataType: 'jsonp',
//jsonp: false,
//cache: true,
success: function (data) {
    console.log('succes');
    console.log(data);
},
error: function (data) {
    console.log('error');
    console.log(data);
}
});

参考:https ://labs.magnet.me/nerds/2015/05/11/importing-google-contacts-with-javascript.html

于 2016-12-28T08:50:04.273 回答