我试图向Google日历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(确定)。任何帮助将不胜感激!
Here is screenshot代表我的ClientID。
答案 0 :(得分:0)
您需要先使用OAuth显示登录提示并获取访问令牌,然后才能联系Calendar API。最简单的方法是使用Google API JavaScript Library。 See this example