-GoogleAPIについてまとめ *公式情報ページ [#se492ab0] |API一覧|https://developers.google.com/apis-explorer/#p/| |ConsoleのAPI設定TOP|https://console.developers.google.com/apis/credentials| |Developer Console|https://console.developers.google.com/cloud-resource-manager?pli=1&authuser=1&creatingProject=true| **GmailAPI [#ia3b7781] -https://github.com/google/mail-importer *認証フローをまとめてみた [#d6ac09b6] **事前準備 [#mfca6a80] -APIの有効化 -OAuth2.0クライアントアカウントの作成(クライアントIDが重要) **Googleアカウントによる認証をへる [#x3fb9a5f] https://accounts.google.com/o/oauth2/auth?client_id={クライアントID}&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/gmail.readonly&response_type=code&approval_prompt=force&access_type=offline **上記画面で認証した後にrefresh_tokenを得る [#m7273025] *GMail APIアクセスまでの手順 [#u35bd2d4] **1.OAuthのクライアントID (サービスアカウントは秘密鍵を利用して認証を挟まない形式) [#cbb0752f] クライアントIDとSecretを取得できる https://console.developers.google.com/apis/credentials?project=プロジェクト名 **サービスアカウントの管理はこちら! [#be3f5f6d] https://console.developers.google.com/iam-admin/serviceaccounts/project?project=プロジェクト名 **2.以下のページにアクセスすると、認証挟んだ後にrefresh_token取得できる。 [#j56190c7] https://accounts.google.com/o/oauth2/auth?client_id=クライアントID&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/gmail.readonly&response_type=code&approval_prompt=force&access_type=offline **3.以下のクエリーでアクセストークン取得 [#s259d60d] curl -d client_id=クライアントID -d client_secret=781ht-pJ4_G1G2jRl7QcJFAP -d redirect_uri=urn:ietf:wg:oauth:2.0:oob -d grant_type=authorization_code -d code=クライアントシークレット https://accounts.google.com/o/oauth2/token **4.アクセストークンの情報確認 [#p43e3696] https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=3で取得したアクセストークン **5.一覧と詳細 [#db1d4b8d] curl -H "Authorization: Bearer 3で取得したアクセストークン" https://www.googleapis.com/gmail/v1/users/me/messages/ *OAuth2.0の解説。ここが一番詳しいかな [#ma4bc272] https://himakan.net/websites/how_to_google_oauth -Gmailの認証もOAuth2.0対応じゃない場合は安全性の低いアプリとみなされてしまう。 *Developer Console [#c4ed5562] *Service Accountを利用したアクセスについて [#td025a55] -FireBaseで使ったものの情報が非常に少ない!公式情報としては下記の通り。 https://developers.google.com/identity/protocols/OAuth2ServiceAccount#delegatingauthority -Google Play APIでも使ってた https://github.com/googlesamples/android-play-publisher-api/blob/master/v2/java/src/com/google/play/developerapi/samples/AndroidPublisherHelper.java -使って見た事例 http://www.yoheim.net/blog.php?q=20160411 *API認証周り [#lc49f6f6] サービスアカウント経由であれば秘密鍵JSONを利用し、OAuth2.0であればClientID/KEYを使う(リダイレクトURLなしを作成するにはその他を選択する) **用語集 [#k9021d24] |CLIENT ID|OAuth 2.0 クライアントID| |CLIENT KEY|OAuth 2.0 クライアントパスワード| *Google Play Console [#ga9aac43] https://developer.android.com/google/play/developer-api.html#subscriptions_api_overview