Java에서 Google fusion 테이블 API를 사용하려고합니다. 400 Bad Request
및 "error" : "invalid_grant"
이 표시됩니다.Google 퓨전 테이블 400 invalid_grant
서비스 계정 API 및 OAuth2.0을 사용하여 요청을 승인하고 있습니다.
1) 내 비밀 키를 다운로드하고 아래의 스 니펫을 자격 증명에 사용합니다.
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(HTTP_TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId("[[[email protected]account.com]]")
.setServiceAccountPrivateKeyFromP12File(KeyResources.INSTANCE.getFileFromPath("b9b48154142d235bbd711c3eb8f86bb2ec155faf-privatekey.p12"))
.setServiceAccountScopes("oauth2:https://www.googleapis.com/auth/fusiontables")
.build();
2) 코드 스 니펫에 연결하는 데 아래 코드를 사용하고 있습니다.
Credential credential = ServiceAccount.INSTANCE.getCredentials();
Fusiontables fusiontables = new Fusiontables.Builder(ServiceAccount.HTTP_TRANSPORT, ServiceAccount.JSON_FACTORY, credential)
.setApplicationName("sfdgdfgdfgdfgdfgdfgf345q23")
.setHttpRequestInitializer(credential)
.build();
Fusiontables.Table.List listTables = fusiontables.table().list();
이것은 내가 얻는 오류입니다.
com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
{
"error" : "invalid_grant"
}
at com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:103)
at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:303)
at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:323)
at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:340)
at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:508)
도움이 될 것입니다.
감사합니다, 가네 V
마지막 린 어느 예외가 throw되기 전에 코드에서 실행되는 e? –
'Fusiontables.Table.List listTables = fusiontables.table(). list();'이것은 코드에서 실행 된 마지막 줄입니다. 이 메소드는 Credential.refreshToken을 호출합니다. 코드에서 직접 Credential.refreshToken을 호출 해 보았습니다. 그리고 이것도 같은 오류를줍니다. –