2

我们想让我们的 GAE for java 应用程序从谷歌驱动器中读取文档以满足应用程序的特定要求。

同样,我试图参考https://developers.google.com/drive/auth/web-server

但是,我无法理解代码流。没有提及从哪里获得授权代码,如下面的代码中所述:

 public static Credential getCredentials(String authorizationCode, String state)
      throws CodeExchangeException, NoRefreshTokenException, IOException {
    String emailAddress = "";
    try {
      Credential credentials = exchangeCode(authorizationCode);
      Userinfo userInfo = getUserInfo(credentials);
      String userId = userInfo.getId();
      emailAddress = userInfo.getEmail();
      if (credentials.getRefreshToken() != null) {
        storeCredentials(userId, credentials);
        return credentials;
      } else {
        credentials = getStoredCredentials(userId);
        if (credentials != null && credentials.getRefreshToken() != null) {
          return credentials;
        }
      }
    } catch (CodeExchangeException e) {

gae for java和google drive之间集成的任何工作示例?

4

1 回答 1

1

如果您尝试离线访问,首先您必须获得授权码,该授权码可用于兑换访问令牌和刷新令牌。

1) 从Google APIs 控制台启用 Google Drive Services

2) 为Web 应用程序创建客户端 ID

然后,获取授权码,例如:

https://accounts.google.com/o/oauth2/auth?access_type=offline
&approval_prompt=auto
&client_id=[your id]
&redirect_uri=[url]
&response_type=code
&scope=[access scopes]
&state=/profile

之后,您可以调用 exchangeCode() ,其参数将是您之前检索到的授权码。

于 2013-08-22T11:42:38.923 回答