404 error on google contacts api

627 Views Asked by At

I want to use google contacts api v3 to get all contacts of account but when i use jquery ajax request, this error happened on every requests :

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);
}
});

I use this doc : https://developers.google.com/google-apps/contacts/v3/

but i think something wrong with https://www.google.com/m8/feeds/contacts/default/full because on any requests result is one thing ! readyState: 4, status: 404, statusText: "error"!

1

There are 1 best solutions below

0
On BEST ANSWER

after searching more and asking my problem from others, added alt=json and accesstoken to url and disable jsonp: false and cache: true because request need jsonp .

working code is something like this :

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);
}
});

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