【发布时间】:2016-01-21 14:58:19
【问题描述】:
我正在尝试向谷歌日历 API 发出 ajax 请求,但出现了问题。 这里我有非常简单的代码,但我不明白为什么它不起作用。
var mykey = 'my server key'; // I am using here server key(which I created in credentials in console.developers.google.com) Maybe I am using wrong version?! I've tried browser key, but it didn't help me.
var calendarid = 'my client_id'; // here I am using VALID clientId, which I created in my project in developer console. Below this code I attached screen.
$.ajax({
type: 'GET',
url: encodeURI('https://www.googleapis.com/calendar/v3/calendars/' + calendarid+ '/events?key=' + mykey),
dataType: 'json',
success: function (response) {
//console.log('Nice!')
},
error: function (response) {
//console.log('Bad!')
}
});
我在浏览器控制台中总是出现错误 404 (OK)。任何帮助将不胜感激!
Here is screenshot 我的 ClientID。
【问题讨论】:
-
AJAX 跨域/来源不正常。应该从服务器调用。或者这可能有效但从未测试过:ajax-cross-origin.com
标签: javascript jquery ajax google-api