1

Java から Google Fusion Tables API を使用しようとしています。と を取得400 Bad Requestして "error" : "invalid_grant"います。

サービス アカウント API と OAuth2.0 を使用してリクエストを承認しています。

1) 秘密鍵をダウンロードし、資格情報に以下のスニペットを使用します。

GoogleCredential credential = new GoogleCredential.Builder()
            .setTransport(HTTP_TRANSPORT)
            .setJsonFactory(JSON_FACTORY)
            .setServiceAccountId("[[293873940759-je0f8o4j90nmqvlbl6ofbtm0492paikd@developer.gserviceaccount.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

4

2 に答える 2

1

サービスアカウントIDの周りの「[]」を削除する必要があると思います。

それとは別に、サービスアカウントIDを変更した後に403不正エラーが発生した場合は、テーブルの編集アクセス権をサービスアカウントに付与していないことが原因である可能性があります。アクセスを変更するには、フュージョンテーブルをサービスアカウントのメールアドレスと共有し、「編集可能」アクセスを許可します。

お役に立てば幸いです。

于 2013-02-28T01:04:25.740 に答える
0

サービス アカウントはユーザー アカウントを委任する必要があるため、ユーザーのメールを設定する必要があると思います。

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

Fusion Tables APIサービスがオンになっていることを確認し、ユーザーの所有者のドメイン コンソールで、サービス アカウントに正しいスコープを付与します。

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

于 2013-08-09T10:13:03.043 に答える