2012-08-22 2 views
1

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

+0

마지막 린 어느 예외가 throw되기 전에 코드에서 실행되는 e? –

+0

'Fusiontables.Table.List listTables = fusiontables.table(). list();'이것은 코드에서 실행 된 마지막 줄입니다. 이 메소드는 Credential.refreshToken을 호출합니다. 코드에서 직접 Credential.refreshToken을 호출 해 보았습니다. 그리고 이것도 같은 오류를줍니다. –

답변

1

나는 당신이 "[]"주위에 당신의 서비스 계정 ID를 제거해야합니다 생각합니다.

그 외에도 서비스 계정 ID를 변경 한 후에 403 번의 인증되지 않은 오류가 발생하는 경우 서비스 계정에 대한 편집 권한을 부여하지 않았기 때문일 수 있습니다. 액세스를 변경하려면 융합 표를 서비스 계정 이메일에 공유하고 "편집 가능"액세스 권한을 부여하면됩니다.

희망이 도움이됩니다.

GoogleCredential credential = new GoogleCredential.Builder() 
      ... 
      .setServiceAccountUser(UserEmail) 

및 서비스 퓨전 테이블 API가 켜져 있는지 확인하고 사용자의 소유자에 :

0

나는 서비스 계정 사용자 계정을 위임 할 필요가 당신이 사용자의 이메일을 설정할 필요가 있다고 생각 도메인 콘솔 서비스 계정에 올바른 범위를 부여합니다

https://www.googleapis.com/auth/fusiontables

관련 문제