0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PostmanでGmailを取得する

Posted at

目的

PostmanでGmailを取得したい。

手順

1. Google Cloud Platfromにアクセスし、Gmail APIを選択する

step1.jpg

2. Gmail APIを有効にする

step2.jpg

3. OAuth クライアントを取得する
  1. 「認証情報を作成>OAuth クライアント ID」を選択する
    step3.jpg
  2. 「OAuth クライアント IDの作成」画面で、以下の内容を選択し「作成」ボタンをクリックする

・アプリケーションの種類:ウェブアプリケーション
・承認済みのリダイレクト URI: https://oauth.pstmn.io/v1/callback
step3-2.jpg
3. OAuthクライアントのクライアントIDとクライアントシークレットをコピーしてメモ帳に控える
step3-3.jpg

4. Postmanを起動し、新規コレクションを作成する

まず、サンプルとしてusers.getProfileリクエストを叩いてみる。
以下のようなレスポンスが返ってくれば成功:

sample.json
{
  "emailAddress": string,
  "messagesTotal": integer,
  "threadsTotal": integer,
  "historyId": string
}

step4.jpg

5. 認証情報を設定する
  1. Authorizationタブを開き、TypeをOAuth 2.0で選択する
    step5.jpg

  2. Access Tokenを取得する
    「Configure New Token」に以下の内容を入力し、「Get New Access Token」ボタンをクリックする。
    ブラウザが起動し、「許可しますか」的な画面が表示されるので許可すると、Access Tokenを取得できる

項目
Grant Type なんでもよい
Callback URL 「Authorize using browser」にチェックを付与する
Auth URL https://accounts.google.com/o/oauth2/v2/auth
Client ID メモ帳に控えたもの
Client Secret メモ帳に控えたもの
Scope https://mail.google.com/ (ほかのAPIを叩く場合はAPIドキュメントのAuthorization Scopesの記載に従って適宜入力すること)
State 空欄
Client Authentication send client cledentials in body
step5-2.jpg
6. リクエストを実行する

画面右上の「Send」ボタンをクリックするとリクエストが実行される。
ドキュメント通りのレスポンスが返ってくればOK
step6.jpg

オマケ:メール一覧を取得し、最新のメールの詳細を取得する

おまけっていうかこっちが本題なんだけど、どちらかというと知りたかったのはstep1-6の流れなので、まぁオマケといえばおまけだと思う。
GitHubにCollectionファイル置いておくので、興味あればどうぞ(リポジトリ)。
step_omake.jpg

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?