Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Gmail API by Node.js
Search
takayukio
June 01, 2015
Programming
390
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Gmail API by Node.js
Node.js を用いて Gmail API を叩くコンソールツールを作成してみよう!
takayukio
June 01, 2015
Other Decks in Programming
See All in Programming
Web Framework Benchmark Battle 2026, Any%
a_matsuda
2
2k
npm との違いを手がかりにGo の依存管理を理解したい
optim
0
290
Rでドレミ/Do-Re-Mi_with_R
florets1
0
130
Workers Cache を知る
syumai
0
360
3回つくってわかった、 定期実行ジョブ基盤の本質情報
takai
0
450
Vue Fes Japan の “作る側”に関わってみて
naokihaba
0
160
AI主導のプログラミング学習アプリを作ってみた
econanringo
0
180
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
1.1k
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
590
作れる、でも消せるか?──安全に「枯らして消す」機能削除術 / Drain, Then Delete
chobishiba
2
630
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
290
Verilogで学ぶCPU自作入門
uyuki234
8
4.1k
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
410
Joys of Absence: A Defence of Solitary Play
codingconduct
1
550
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
Paper Plane (Part 1)
katiecoart
PRO
2
12k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
310
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.7k
How to build a perfect <img>
jonoalderson
1
6.1k
Fireside Chat
paigeccino
43
4.1k
Faster Mobile Websites
deanohume
310
32k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Transcript
Gmail API by Node.js 18:00 ~ 20:30 givery, Inc. Takayuki
Oda
小田 崇之 (Takayuki Oda) Givery ・Back-end Engineer ・Scala やってる事 ・社会人
・キャンプのカウンセラー ・ボルダリング(やりたい) その他 da0shi おだし アダ名
目次 • ~ 18:10 イントロ • ~ 18:15 自己紹介 •
~ 18:25 今回持って帰ってほしいもの • ~ 19:55 実習 (GmailAPI by Node.js) • ~ 20:05 終わりに
今回持って帰ってほしいもの Node.js への興味 REST API への興味 自分が挑戦した軌跡 自分で学んでいく方法
実習
作るもの Node.js を使ったコマンドラインツール Gmail API にアクセスするツール
目標 未読のメールを取得する
流れ • npm プロジェクトを作る • Gmail API について知る • [実装]
トークンを取得する • [実装] REST API を使ってみる
流れ • npm プロジェクトを作る • Gmail API について知る • [実装]
トークンを取得する • [実装] REST API を使ってみる
create npm project $ mkdir cmail $ git init $
npm init
edit package.json コマンドライン用に修正 ヒント:bin プロパティ
edit package.json 追加: "preferGlobal": true "bin": "index.js" 削除: "main": "index.js"
index.js #!/usr/bin/env node 'use strict'; console.log("Hello Cmail"); console.log(process.argv); console.log(process.env.HOME);
npm link $ npm link $ cmail
流れ • npm プロジェクトを作る • Gmail API について知る • [実装]
トークンを取得する • [実装] REST API を使ってみる
Gmail API について知る REST API OAuth
REST API HTTP の性質を利用したデータのやりとり Request でパラメータを渡す Response でデータを返す URLそのものがどんなデータなのかを表す
OAuth アプリケーションの認証の仕組み 第3者にパスワードを渡す事なく認証する 鍵となる Token を発行して認証 Token を発行するために API Key
が必要 "Google Developers Console"
Google Developers Console 新しいクライアントIDを作成 インストール -> その他 JSON をダウンロード
Token 生成の手順 Token 生成の手順を調べよう 検索タイム
Token 生成の手順 ???
Token 生成の手順 gmail api oauth token
None
http://qiita.com/giiko_/items/b0b2ff41dfb0a62d628b
流れ • npm プロジェクトを作る • Gmail API について知る • [実装]
トークンを取得する • [実装] REST API を使ってみる
npm install —save fs request querystring readline-sync open
Token 生成の手順 code を取得するためのURLを生成 URLにアクセス・認証して code を取得 token を取得するためのURLを生成 Request
を送って Response から token 取得
code 取得に必要な情報 公式ドキュメントやさっきのページを見ながら
code 取得に必要な情報 response_type -> 'code' client_id redirect_uri scope -> readonly
access_type -> 'offline' approval_prompt -> 'force'
公式ドキュメントやさっきのページを見ながら token 取得に必要な情報
token 取得に必要な情報 code client_id client_secret redirect_uri grant_type -> 'authorization_code'
流れ • npm プロジェクトを作る • Gmail API について知る • [実装]
トークンを取得する • [実装] REST API を使ってみる
お題 未読のメールを5件取得して表示する
調べること Token の渡し方
Token の渡し方 公式ドキュメントを見てみよう https://developers.google.com/gmail/ api/v1/reference/query-parameters
Token の渡し方 Query Parameters を活用 キー名はaccess_token http://some.url.com? access_token={:token}
メッセージを取得 公式ドキュメントを見てみよう https://developers.google.com/gmail/ api/v1/reference/users/messages/get https://developers.google.com/gmail/ api/v1/reference/users/messages/list
メッセージ一覧を取得 • method: GET • endpoint: https://www.googleapis.com/gmail/ v1/users/me/messages
メッセージを取得 • method: GET • endpoint: https://www.googleapis.com/gmail/ v1/users/me/messages/{:messageId}
流れ • npm プロジェクトを作る • Gmail API について知る • [実装]
トークンを取得する • [実装] REST API を使ってみる
終わりに 自分の興味を殺さないこと 小さく進むこと 自分が進んだ軌跡を残すこと
ちなみに 今回のコードは https://github.com/da0shi/cmail.git で絶賛公開中