Javascript 未经宣誓就将谷歌日历事件插入我的议程

Javascript 未经宣誓就将谷歌日历事件插入我的议程,javascript,rest,google-api,google-calendar-api,Javascript,Rest,Google Api,Google Calendar Api,我正在创建一个议程系统,在谷歌日历API中列出并创建事件, 我已使用以下代码成功检索: var mykey = 'your_api_key'; // typically like Gtg-rtZdsreUr_fLfhgPfgff var calendarid = 'you_calendar_id'; // will look somewhat like 3ruy234vodf6hf4sdf5sd84f@group.calendar.google.com $.ajax({ type: '

我正在创建一个议程系统,在谷歌日历API中列出并创建事件, 我已使用以下代码成功检索:

var mykey = 'your_api_key'; // typically like Gtg-rtZdsreUr_fLfhgPfgff
var calendarid = 'you_calendar_id'; // will look somewhat like 3ruy234vodf6hf4sdf5sd84f@group.calendar.google.com

$.ajax({
    type: 'GET',
    url: encodeURI('https://www.googleapis.com/calendar/v3/calendars/' + calendarid+ '/events?key=' + mykey),
    dataType: 'json',
    success: function (response) {
        //do whatever you want with each
    },
    error: function (response) {
        //tell that an error has occurred
    }
});

现在我需要插入事件,我能找到的所有内容都需要宣誓,主要是关于在用户日历上保存事件,而我只想将其保存在我的日历中。有什么建议吗?

您可以使用服务帐户=>

  • 创建服务帐户

  • 为您的服务帐户创建一个密钥(JSON应该可以工作)

  • 为您的服务帐户提供对所需日历范围的访问

    • 转到安全->API控件->域范围的委派
    • 例如,添加作用域
  • 调用API时,使用JSON(JWT=>JSON Web令牌)文件进行身份验证

在日历所在的帐户中,您必须提供从日历到服务帐户编辑事件的权限

这里提供了使用服务帐户的HTTP/Rest的所有步骤和代码示例