2013-06-12 109 views
2

我們想讓我們的GAE for java應用程序從谷歌驅動器讀取文檔以瞭解應用程序的特定要求。實施服務器端授權到谷歌驅動器的問題

出於同樣的,我想是指https://developers.google.com/drive/auth/web-server

但是,我無法理解的代碼流。沒有提到像從哪裏獲得authorizationCode如下面的代碼中提到:

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之間的集成Java和谷歌的任何工作示例開車嗎?

回答

1

如果您嘗試進行離線訪問,首先必須獲取授權碼,這些授權碼可能會被兌換爲訪問令牌和刷新令牌。

1)Google APIs console

2)創建web applications

客戶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 (),它的參數將是您以前檢索的授權碼。

+0

我試過了,並且在獲取refreshToken時遇到了問題。請通知http://stackoverflow.com/questions/17333726/refreshtoken-is-null – Vik

相關問題