2011-12-20 24 views
1

我有這樣的錯誤:GAE的OAuth的Java:無認證標頭信息

WARNING: Authentication error: Unable to respond to any of these challenges: {} 
Exception : No authentication header information 

我使用GWT使用Eclipse。 我真的不知道我的代碼中有什麼問題。 任何幫助,將不勝感激。

在此先感謝。

客戶端入口點類:

private static final String GOOGLE_AUTH_URL = "https://accounts.google.com/o/oauth2/auth"; 
private static final String GOOGLE_CLIENT_ID = "xxxxxxx.apps.googleusercontent.com"; 
private static final String CONTACTS_SCOPE = "https://www.google.com/m8/feeds"; 
private static final Auth AUTH = Auth.get(); 

public void onModuleLoad() { 
     final AuthRequest req = new AuthRequest(GOOGLE_AUTH_URL, GOOGLE_CLIENT_ID).withScopes(CONTACTS_SCOPE); 

    AUTH.login(req, new Callback<String, Throwable>() { 
     public void onSuccess(String token) {    
      ABASession.setToken(token); 
     } 

     public void onFailure(Throwable caught) { 
      Window.alert("Error:\n" + caught.getMessage()); 
     } 
    }); 
} 

我令牌存儲裝置中,我將在以後使用的類。

服務器端:ContactServiceImpl(RPC GAE程序)

//以前存儲的令牌,然後通過RPC傳遞 公開名單printAllContacts(字符串令牌){ 嘗試{ GoogleOAuthParameters oauthParameters =新GoogleOAuthParameters() ;

 oauthParameters.setOAuthConsumerKey("My consumer key"); 
     oauthParameters.setOAuthConsumerSecret("My consumer secret"); 

     PrivateKey privKey = getPrivateKey("certificate/akyosPrivateKey.key"); 

     OAuthRsaSha1Signer signer = new OAuthRsaSha1Signer(privKey); 

     ContactsService service = new ContactsService("XXX"); 
     service.setProtocolVersion(ContactsService.Versions.V3); 
     oauthParameters.setOAuthToken(token); 
     service.setOAuthCredentials(oauthParameters, signer); 

     // Request the feed 
     URL feedUrl = new URL("http://www.google.com/m8/feeds/contacts/default/f[email protected]"); 

     ContactFeed resultFeed = service.getFeed(feedUrl, ContactFeed.class); 
     for (ContactEntry entry : resultFeed.getEntries()) { 
      for (Email email : entry.getEmailAddresses()) { 
       contactNames.add(email.getAddress()); 
      } 
     } 
     return contactNames; 
    } catch (Exception e) { 
     System.err.println("Exception : " + e.getMessage()); 
    } 
    return null; 
} 

回答

1

設定範圍

oauthParameters.setScope("http://www.google.com/m8/feeds/contacts/default/full");