Created
November 16, 2012 23:14
-
-
Save thinkAmi/4091800 to your computer and use it in GitHub Desktop.
Google App EngineでGoogle Calendar API v3 を使うときのサンプル (Pythonファイルのみ)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
関連Blogはこちら
http://d.hatena.ne.jp/thinkAmi/20121117/1353107840