GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(HTTP_TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId("sam...@xxxxxx.iam.gserviceaccount.com")
.setServiceAccountScopes(SCOPES)
.setServiceAccountUser("{Google Apps のユーザー名(メールアドレス)}")
.setServiceAccountPrivateKeyFromP12File(new File("key.p12"))
.build() ;
credential.refreshToken() ;
String accessToken = credential.getAccessToken() ;
String refreshToken = credential.getRefreshToken() ; ← これが null になる
たしかそのはずです。
公式ドキュメントにも以下のように書いてます。
https://developers.google.com/identity/protocols/OAuth2#serviceaccount
"When the token expires, the application repeats the process"
--
このメールは Google グループのグループ「Google Apps API Japan」に登録しているユーザーに送られています。
このグループから退会し、グループからのメールの配信を停止するには google-apps-api-...@googlegroups.com にメールを送信してください。
このグループに投稿するには google-app...@googlegroups.com にメールを送信してください。
その他のオプションについては https://groups.google.com/d/optout にアクセスしてください。
{
"access_token" : "1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M",
"token_type" : "Bearer",
"expires_in" : 3600
}
たしかそのはずです。
公式ドキュメントにも以下のように書いてます。
https://developers.google.com/identity/protocols/OAuth2#serviceaccount"When the token expires, the application repeats the process"
2016/07/20 (水) 1:35PM wezardnet <wezard...@gmail.com>:
--お世話になります wezardnet です。Service Account を使って Google API を利用する時に、次のように GoogleCredential を生成してアクセストークンを取得しています。
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(HTTP_TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId("sam...@xxxxxx.iam.gserviceaccount.com")
.setServiceAccountScopes(SCOPES)
.setServiceAccountUser("{Google Apps のユーザー名(メールアドレス)}")
.setServiceAccountPrivateKeyFromP12File(new File("key.p12"))
.build() ;
credential.refreshToken() ;
String accessToken = credential.getAccessToken() ;
String refreshToken = credential.getRefreshToken() ; ← これが null になる
アクセストークンの有効期限切れの場合、リフレッシュトークンを使って再発行するのが通常の OAuth の流れになると思うのですが、初回にリフレッシュトークンが取得できません。Service Account の場合は、毎回アクセストークンを取得するモノなのでしょうか?毎回取得していると Google Apps のトークン監査ログに取得のたびに、「XXXX さんが ****** のスコープについて Application Name へのアクセスを承認しました」とログが残るのであまり良い気はしないです。
このメールは Google グループのグループ「Google Apps API Japan」に登録しているユーザーに送られています。
このグループから退会し、グループからのメールの配信を停止するには google-apps-api-japan+unsub...@googlegroups.com にメールを送信してください。
お世話になります wezardnet です。Service Account を使って Google API を利用する時に、次のように GoogleCredential を生成してアクセストークンを取得しています。
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(HTTP_TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountScopes(SCOPES)
.setServiceAccountUser("{Google Apps のユーザー名(メールアドレス)}")
.setServiceAccountPrivateKeyFromP12File(new File("key.p12"))
.build() ;
credential.refreshToken() ;
String accessToken = credential.getAccessToken() ;
String refreshToken = credential.getRefreshToken() ; ← これが null になる