如何使用v3 API和JQuery将事件添加到Google日历? [英] How can I add an event to a Google calendar using v3 API and JQuery?

查看:64
本文介绍了如何使用v3 API和JQuery将事件添加到Google日历?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过组合一个简单的页面来教给自己一些JQuery/REST/Google API:

I am attempting to teach myself some JQuery/REST/Google API by putting together a simple page that does the following:

  1. 通过Google验证
  2. 验证令牌
  3. 获取该用户的Google日历列表
  4. 列出所选日历的事件
  5. 为选定的日历添加事件

我的#1到#4工作正常(尽管毫无疑问,这很丑陋),但我却陷入了#5的困境.这是JQuery ajax调用:

I have #1 through #4 working (although no doubt in an ugly manner), and am getting tripped up on #5. Here's the JQuery ajax call:

var url = 'https://www.googleapis.com/calendar/v3/calendars/[MY_CALENDAR_ID]/events?sendNotifications=false&access_token=[GOOGLE_API_TOKEN]';
            var data = { end: { dateTime: "2012-07-22T11:30:00-07:00" }
                            , start: { dateTime: "2012-07-22T11:00:00-07:00" }
                            , summary: "New Calendar Event from API"
                        };

            var ajax = $.ajax({ url: url
                                , data: data
                                , type: 'POST'
                        }).done(addEventDone)
                          .fail(function (jqHXR, textStatus) {
                              console.log("addEvent(): ajax failed = " + jqHXR.responseText);
                              console.log(jqHXR);
                          });

结果是全局parseError:此API不支持解析表单编码的输入.".前四个步骤都使用GET ajax调用,所以我不确定这是否使我感到困惑.

The results are a global parseError: "This API does not support parsing form-encoded input.". The first four steps are all using GET ajax calls, so I'm not sure if that is what is tripping me up.

这里是有问题的API: https://developers. google.com/google-apps/calendar/v3/reference/events/insert

Here's the API in question: https://developers.google.com/google-apps/calendar/v3/reference/events/insert

我认为我可能会做长而艰难的事情,而我的新方法是使用javascript API解决此问题,而不是直接使用手动JQuery和REST来解决.这是我正在尝试的方法 http://code.google.com/p/google-api-javascript-client/wiki/Samples#Calendar_API ,尽管如果我有一些简单的事情要解决,我仍然很乐意将其作为学习的机会以上.

I think I may be doing things the long and hard way, and my new approach is to tackle this using the javascript API instead of going straight at it with manual JQuery and REST. This is the approach I am attempting going forward http://code.google.com/p/google-api-javascript-client/wiki/Samples#Calendar_API, although I would still love to use this as a learning opportunity if there is something simple I am screwing up in the code above.

感谢您的帮助,见解,指示等.如果使用javascript API取得任何进展,我将发布更新.

Thanks for any help, insights, pointers, etc. I will post updates if I make any progress using the javascript API.

推荐答案

有趣的是,我刚刚回答了类似的问题

Interestingly, I just answered a similar question here. Your intuition to use Google's JS client library is a good one. It's going to handle OAuth 2 for you, which is a requirement if you're going to do any manipulation of the Calendar data.

我的其他答案都具有指向博客文章(演示了客户端的配置和用户授权),以及插入Calendar事件的示例.

My other answer has both a link to a blog post that I authored (which demonstrates configuration of the client and user authorization), as well as an example of inserting a Calendar event.

这篇关于如何使用v3 API和JQuery将事件添加到Google日历?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆