Vik
Vik

Reputation: 9319

Issues in implementing server side authorization to google drive

We want to let our GAE for java app to read docs from google drive for the app specific requirements.

For the same I was trying to refer https://developers.google.com/drive/auth/web-server

However, I am unable to understand the code flow. There is no mention like from where to obtain the authorizationCode as mentioned in the code below:

 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) {

Any working example of integration between gae for java and google drive?

Upvotes: 2

Views: 590

Answers (1)

grep
grep

Reputation: 5623

if you try to have offline access, first of all you must get authorization code which may be redeemed for an access token and a refresh token.

1) Enable Google Drive Services from Google APIs console

2) Create Client ID for web applications

then , get authorization code, for instance:

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

after that, you can call exchangeCode() , and its parameter will be your authorization code that was retrieved before.

Upvotes: 1

Related Questions