404 ошибка в контактах Google API
Я хочу использовать 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"
!
1 ответ
Решение
После поиска больше и выяснения моей проблемы от других, добавил alt=json
и доступ к URL и отключить jsonp: false
а также cache: 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