需要一个很好的例子:JavaScript中的Google Calendar API [英] Need good example: Google Calendar API in Javascript

查看:80
本文介绍了需要一个很好的例子:JavaScript中的Google Calendar API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做的事情: 使用javascript从我的网站向Google日历添加事件.

What I'm trying to do: Add events to a google calendar from my site using javascript.

我不能做的事情: 为Google Calendar API找到一个不错的教程/演练/示例.我已经能够找到在v1和v2 api之间来回链接的所有文档,或者v3 api似乎不是基于客户端的.

What I can't do: Find a good tutorial/walk through/example for the google calendar api. All the documentation I've been able to find links back and forth between v1 and v2 api's, or the v3 api doesn't seem to be client based.

对于那些好奇的人,我正在为此开发网站: http://infohost.nmt.edu/~bbean/banweb/index.php

For those that are curious, the site I'm developing this for: http://infohost.nmt.edu/~bbean/banweb/index.php

推荐答案

Google提供了一个出色的JS客户端库,该库可与Google的所有基于发现的API(例如Calendar API v3)一起使用.我写了一个博客文章,涵盖了设置JS客户端和授权用户的基础知识.

Google provides a great JS client library that works with all of Google's discovery-based APIs (such as Calendar API v3). I've written a blog post that covers the basics of setting up the JS client and authorizing a user.

一旦在应用程序中启用了基本客户端,就需要熟悉Calendar v3的细节才能编写应用程序.我建议两件事:

Once you have the basic client enabled in your application, you'll need to get familiar with the specifics of Calendar v3 to write your application. I suggest two things:

  • API浏览器将向您显示API中可用的调用. /li>
  • 当您操作gapi.client时,Chrome开发人员工具的Javascript控制台会自动建议方法名称.例如,开始键入gapi.client.calendar.events.,您应该会看到一组可能的补全(您需要insert方法).
  • The APIs Explorer will show you which calls are available in the API.
  • The Chrome developer tools' Javascript console will automatically suggest method names when you are manipulating gapi.client. For example, begin typing gapi.client.calendar.events. and you should see a set of possible completions (you'll need the insert method).

以下是将事件插入JS的示例:

Here's an example of what inserting an event into JS would look like:

var resource = {
  "summary": "Appointment",
  "location": "Somewhere",
  "start": {
    "dateTime": "2011-12-16T10:00:00.000-07:00"
  },
  "end": {
    "dateTime": "2011-12-16T10:25:00.000-07:00"
  }
};
var request = gapi.client.calendar.events.insert({
  'calendarId': 'primary',
  'resource': resource
});
request.execute(function(resp) {
  console.log(resp);
});

希望这足以帮助您入门.

Hopefully this is enough to get you started.

这篇关于需要一个很好的例子:JavaScript中的Google Calendar API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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