Google Drive push notifications를 hubot에서 받기
6906 단어 HubotCoffeeScript
특정 드라이브 폴더의 변경을 알립니다.
서비스 계정 만들기
Google Developers Console 에서 프로젝트 선택 또는 프로젝트 작성

서비스 계정으로 만들기

webmaster에서 도메인 소유자를 등록해야합니다
폴더 공유

푸시를 받는 사이트 설정
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
coffeescript에서 수행하는 샘플
googleapis = require('googleapis')
drive = googleapis.drive({version: 'v2'})
SERVICE_ACCOUNT_EMAIL = '[email protected]'
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
서비스 계정에 공유 한 폴더 아래에서 파일을 변경하면
https://上記でプッシュ設定したドメイン/google/drive/notifications
에 알림이 표시됩니다.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
Reference
이 문제에 관하여(Google Drive push notifications를 hubot에서 받기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/hotakasaito/items/824b7612667e32328345텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)