はじめに
Google APIs を使うコマンドラインを書いてみました。自分のイベントとか見たい方は適当に改良してください。:-)
** かぶりネタですが興味のある方は読んでください。**
Usage
USAGE
gapicalendarlist.sh v2|v3
RESET SETTINGS
remove 'v2.gapi.token' or 'v3.gapi.token'
DEPENDENCIES
lynx, curl
解説のようなメモのような
簡単に認証と処理内容を書いてみました
認証の種類
- Version 2 : using ClientLogin
-
- OAuth
- AuthSub
- ClientLogin
- Version 3 : using OAuth -> Devices
-
知識の足りなさ等の諸事情で Devices の方法を選択してます。
Installed Applicatoinsの方式で、https://accounts.google.com/o/oauth2/authにリクエストするとHTMLコンテンツがかえって来ます。これはシェルであれこれするのが面倒だったのでやめました。
Devices方式で、https://accounts.google.com/o/oauth2/device/codeにリクエストをすると、JSONがかえってpiar毎に改行されているのでシェルで扱いやすいのでこちらを選択しました- OAuth
- Login
- Web Server Applications
- Client-size Applications
- Installled Applications (Winwdows, iOS, Android, Blackberry)
- Devices
- Service Accounts
- OAuth
処理内容
*** Google のサイトを見た方がいいと思ったので割愛します。 ***
[ shell ] [ google ]
| |
| |
+----- get user token -----> + URL 1
| |
| <------ user token --------+
| and other params |
| JSON |
| |
+----+ |
| | save token |
|<---+ |
| [ lynx ] |
| | |
+-- verify ->| |
| URL +-- Sign in --> |
| | |
| |<- user code --+
| | form |
| | |
| +- user code -->|
| | |
| |<- allow acces-+
| | confirm page |
| | |
| +-allow submit->|
| | |
| |<- result page-+
| | |
| |
| |
| |
| |
+------ get access token --->+ URL 2
| |
| <------ access token ------+
| and other params |
| JSON |
| |
+----+ |
| | save token |
|<---+ |
| |
| |
+----- get calendar list --->+ URL 3
| |
| <----- calendar list ------+
| JSON |
| |
| |
URL 1 https://accounts.google.com/o/oauth2/device/code
URL 2 https://accounts.google.com/o/oauth2/token
URL 3 https://www.googleapis.com/calendar/v3/users/me/calendarList
Reference Link
Source & Screen cast
ttyplay