2

私たちの GAE アプリケーションでは、Google ドライブでユーザーのドキュメントを処理します。このプロセスには 30 秒以上かかる場合があるため、GAE フロントエンド インスタンスであるため、期限の例外が発生します。

バックエンド インスタンスを使用したいと考えています。問題は、資格情報 (com.google.api.client.auth.oauth2.Credentials) を渡して Google ドライブ API を初期化する方法です。

ユーザー認証情報を GAE タスク キューに渡し、次にバックエンド インスタンスに渡して、後でタスクの実行時にそれらを使用できるようにする方法は?

com.google.api.client.auth.oauth2.Credentials is not serializable ...

方法はありますか?

4

2 に答える 2

2

You'll need to keep the inputs to the credential so you can re-create it in the backend handler.

This is either an authorization code, or the access token and refresh token that you got in exchange for the authorization code. They're all strings so should serialize readily.

If all that sounds unfamiliar, I'd be curious to understand how you got the Credential in the first place. Links to useful documentation below:

Notably, sample code in that last link specifically includes a method that you're expected to implement to squirrel away the access/refresh tokens:

/**
 * Retrieved stored credentials for the provided user ID.
 *
 * @param userId User's ID.
 * @return Stored Credential if found, {@code null} otherwise.
 */
static Credential getStoredCredentials(String userId) {
  // TODO: Implement this method to work with your database. Instantiate a new
  // Credential instance with stored accessToken and refreshToken.
  throw new UnsupportedOperationException();
}
于 2013-01-23T09:09:30.433 に答える
0

アクセス トークンとリフレッシュ トークンを格納するには、AppEngineCredentialStoreを使用することをお勧めします。使用例としてcalendar-appengine-sampleをご覧ください。Utils.javaのコード スニペットの例を次に示します。

  static GoogleAuthorizationCodeFlow newFlow() throws IOException {
    return new GoogleAuthorizationCodeFlow.Builder(
        HTTP_TRANSPORT,
        JSON_FACTORY,
        getClientCredential(),
        Collections.singleton(CalendarScopes.CALENDAR))
        .setCredentialStore(new AppEngineCredentialStore())
        .setAccessType("offline")
        .build();
  }

注: 私はgoogle-api-java-clientプロジェクトの所有者です。

于 2013-01-26T17:06:24.790 に答える