Skip to content

Instantly share code, notes, and snippets.

@hotakasaito
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hotakasaito/cac43165889249412654 to your computer and use it in GitHub Desktop.
Save hotakasaito/cac43165889249412654 to your computer and use it in GitHub Desktop.
Google Drive push notifications を hubot で受ける ref: http://qiita.com/hotakasaito/items/824b7612667e32328345
robot.router.post "/google/drive/notifications", (req, res) ->
robot.logger.debug req
# 何かしらの処理
res.status(200).send 'ok'
openssl pkcs12 -in xxx.p12 -nocerts -passin pass:notasecret -nodes -out xxx.pem
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
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