Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Google App EngineでGoogle Calendar API v3 を使うときのサンプル (Pythonファイルのみ)
# -*- coding: utf-8 -*-
import webapp2
import os
import yaml
from apiclient.discovery import build
from oauth2client.appengine import OAuth2Decorator
api_key = yaml.safe_load(open('api.yaml').read().decode('utf-8'))
decorator = OAuth2Decorator(
client_id=api_key['client_id'],
client_secret=api_key['client_secret'],
scope='https://www.googleapis.com/auth/calendar',
)
class CalendarHandler(webapp2.RequestHandler):
@decorator.oauth_required
def get(self):
service = build('calendar', 'v3')
event = self._create_event()
request = service.events().insert(
calendarId=api_key['calendar_id'],
body=event)
http = decorator.http()
response = request.execute(http=http)
def _create_event(self):
event = {
'summary': 'testEvent',
'start': {
'dateTime': '2012-11-17T10:00:00.000',
'timeZone': 'Asia/Tokyo'
},
'end': {
'dateTime': '2012-11-17T11:00:00.000',
'timeZone': 'Asia/Tokyo'
},
}
return event
debug = os.environ.get('SERVER_SOFTWARE', '').startswith('Dev')
app = webapp2.WSGIApplication([
('/', CalendarHandler),
(decorator.callback_path, decorator.callback_handler()),
],
debug=debug)
@thinkAmi
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment