2013-05-20 17 views
1

我收到AuthSub令牌並使用它從Google中檢索所有聯繫人。代碼片段使用Google Contacts API時沒有驗證標頭信息錯誤Java

try { 
    URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/default/base?max-results=" + maxresult); 
    ContactsService service = new ContactsService("Google-contactsExampleApp-1"); 
    service.setAuthSubToken(sessionToken, getPrivateKey()); 

    ContactFeed resultFeed = service.getFeed(feedUrl, ContactFeed.class); 
    ArrayList<UserContact> ucList = new ArrayList<UserContact>(resultFeed.getEntries().size()); 
    for (ContactEntry entry : resultFeed.getEntries()) { 
     if (entry == null || entry.hasDeleted()) { 
      continue; 
     } 
     ucList.add(parseEntry(entry)); 
    } 
    return ucList; 
} catch (Exception e) { 
    LOGGER.log(Level.WARNING, null, e); 
    return null; 
} 

但我得到以下錯誤:

java.lang.NullPointerException: No authentication header information 
at com.google.gdata.util.AuthenticationException.initFromAuthHeader(AuthenticationException.java:96) 
at com.google.gdata.util.AuthenticationException.<init>(AuthenticationException.java:67) 
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:600) 
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563) 
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552) 
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530) 
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535) 
at com.google.gdata.client.Service.getFeed(Service.java:1135) 
at com.google.gdata.client.Service.getFeed(Service.java:998) 
at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:631) 
at com.google.gdata.client.Service.getFeed(Service.java:1017) 

回答

0

我相信你需要調用setOAuthCredentials,以獲得訪問。下面是相同的樣本:

GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters(); 
oauthParameters.setOAuthConsumerKey(consumerKey); 
oauthParameters.setOAuthToken(accessToken); 
contactsService.setOAuthCredentials(oauthParameters, signer); 
+0

尚未轉移到oauth。這是這個問題。對於AuthSubtoken,我注意到要設置的任何憑證。 感謝您的回答 – shoekan

0

試試這個供稿網址,隨時補充,而不是默認和訪問令牌身份驗證的電子郵件ID。

feedUrl = new URL("https://www.google.com/m8/feeds/contacts/"+userEmail+"/full?access_token="+access);