1

我正在研究来自 Google API 客户端的代码,以便能够为 Google 组中的用户提供服务,但我在代码中有两个问题。

例子

  /**
   * Exchange an authorization code for OAuth 2.0 credentials.
   *
   * @param authorizationCode Authorization code to exchange for OAuth 2.0
   *        credentials.
   * @return OAuth 2.0 credentials.
   * @throws CodeExchangeException An error occurred.
   */
  static Credential exchangeCode(String authorizationCode)
      throws CodeExchangeException {
    try {
      GoogleAuthorizationCodeFlow flow = getFlow();
      GoogleTokenResponse response =
          flow.newTokenRequest(authorizationCode).setRedirectUri(REDIRECT_URI).execute();
      return flow.createAndStoreCredential(response, null);
    } catch (IOException e) {
      System.err.println("An error occurred: " + e);
      throw new CodeExchangeException(null);
    }
  }

片段显示:

flow.createAndStoreCredential (response, null);
  1. 它究竟是做什么的?存储在数据库中还是内存中?什么是数据库?
  2. 其中 null 作为参数,可以传递一个 userId。如何让这个用户 ID 作为参数传递?

来源:https ://developers.google.com/drive/training/drive-apps/auth/credentials

4

0 回答 0