Java GoogleドライブAPIを使用します。 私はこのコードを試してみました:com.google.api.client.auth.oauth2.TokenResponseException:401 Unauthorized
public Drive getDriveService() throws GeneralSecurityException, IOException, URISyntaxException
{
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory JSON_FACTORY = new JacksonFactory();
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId("[email protected]")
.setServiceAccountPrivateKeyFromP12File(new java.io.File("C:\\buffer\\sonora project-3256770463ed.p12"))
.setServiceAccountScopes(Collections.singleton(SQLAdminScopes.SQLSERVICE_ADMIN))
.setServiceAccountUser("[email protected]")
.build();
Drive service = new Drive.Builder(httpTransport, JSON_FACTORY, null)
.setApplicationName("FileListAccessProject")
.setHttpRequestInitializer(credential).build();
return service;
}
をしかし、私はこのエラーを取得する:
An error occurred: com.google.api.client.auth.oauth2.TokenResponseException: 401 Unauthorized
私はこの設定を使用します。
あなたは、私はこの問題を解決することができますどのようにいくつかのアイデアを与えることができます?
Iドンを理解するのに役立つことができると思い、他のSOの質問をしていますあなたはできると思いますドメイン管理者アカウントで管理者アカウントにサービスアカウントを追加し、そのユーザーが管理者アカウントのユーザーでない限り、setServiceAccountUserを使用してください。 – DaImTo
投げている合計エラーと例外を教えてもらえますか? – Coder