Spring MVCで書かれたバックエンドからGoogleスプレッドシートにアクセスしようとしています。これは「作業」が、されてhttps://developers.google.com/sheets/quickstart/javaSpring MVCからGoogleスプレッドシートにアクセス
アプリケーションの出力はリンクを私に提供:
public static Sheets getSheetsService() throws IOException {
return new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY, authorize())
.setApplicationName(APPLICATION_NAME)
.build();
}
public static Credential authorize() throws IOException {
// Load client secrets.
InputStream in =
ConcreteSheetsController.class.getResourceAsStream("/secret.json");
GoogleClientSecrets clientSecrets =
GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
// Build flow and trigger user authorization request.
GoogleAuthorizationCodeFlow flow =
new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
.setDataStoreFactory(DATA_STORE_FACTORY)
.setAccessType("offline")
.build();
Credential credential = new AuthorizationCodeInstalledApp(
flow, new LocalServerReceiver()).authorize("user");
System.out.println(
"Credentials saved to " + DATA_STORE_DIR.getAbsolutePath());
return credential;
}
作成された秘密は、それがここで説明されている方法である:チュートリアルを使用して私はこのような何かを得ます。私がそれをクリックすると、ブラウザは私にGoogleアカウントを選択するように頼みます。私がそうすれば、すべてうまくいくが、私はサーバーにもっと適したソリューションを持っていたいと思う。自分の秘密のjson-fileを使用して、私のアプリケーションが私自身のユーザーアカウントを提供せずにログインできるようにしたいと思います。その仕事をする方法はありますか?
あなたは(https://developers.google.com/identity/protocols/OAuth2ServiceAccount)[サーバアプリケーションへのサーバーのためのOAuth 2.0]使用中のサービスアカウントを見て試すことができます。特に、クラウドAPIを呼び出してユーザー固有のデータではなくプロジェクトベースのデータにアクセスする場合は、API呼び出しを行うことができます。 – noogui