Last active
August 29, 2015 14:22
-
-
Save hotakasaito/cac43165889249412654 to your computer and use it in GitHub Desktop.
Google Drive push notifications を hubot で受ける ref: http://qiita.com/hotakasaito/items/824b7612667e32328345
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
robot.router.post "/google/drive/notifications", (req, res) -> | |
robot.logger.debug req | |
# 何かしらの処理 | |
res.status(200).send 'ok' |
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
openssl pkcs12 -in xxx.p12 -nocerts -passin pass:notasecret -nodes -out xxx.pem |
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
googleapis = require('googleapis') | |
drive = googleapis.drive({version: 'v2'}) | |
SERVICE_ACCOUNT_EMAIL = 'xxx@developer.gserviceaccount.com' | |
SERVICE_ACCOUNT_KEY = 'xxx.pem' | |
SCOPE = [ | |
"https://www.googleapis.com/auth/drive", | |
"https://www.googleapis.com/auth/drive.file", | |
"https://www.googleapis.com/auth/drive.readonly", | |
"https://www.googleapis.com/auth/drive.metadata.readonly", | |
"https://www.googleapis.com/auth/drive.appdata", | |
"https://www.googleapis.com/auth/drive.apps.readonly", | |
"https://www.googleapis.com/auth/drive.metadata", | |
] | |
jwt = new googleapis.auth.JWT(SERVICE_ACCOUNT_EMAIL, SERVICE_ACCOUNT_KEY, null, SCOPE) | |
resource = {id: 'watch-001', type: 'web_hook', address: 'https://上記でプッシュ設定したドメイン/google/drive/notifications'} | |
jwt.authorize (err, tokens) -> | |
if err | |
console.log err | |
else | |
jwt.credentials = tokens | |
drive.changes.watch {auth: jwt, resource: resource}, (err, resp) -> | |
if err | |
console.log err | |
else | |
console.log resp |
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
2015-06-11T03:15:35.450146+00:00 heroku[router]: at=info method=POST path="/google/drive/notifications" host=xxx.herokuapp.com request_id=4660b262-e65b-42bc-bfad-06a9a290c292 fwd="xx.xx.xx.xx" dyno=web.1 connect=0ms service=6ms status=200 bytes=164 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment