【问题标题】:Make an ajax request to google calendar api向谷歌日历 API 发出 ajax 请求
【发布时间】: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


【解决方案1】:

您需要使用 OAuth 显示登录提示并获取访问令牌,然后才能联系日历 API。最简单的方法是使用Google API JavaScript LibrarySee this example.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-17
    • 2016-04-15
    • 1970-01-01
    相关资源
    最近更新 更多