2013-05-20 2 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

이 피드 URL을 사용해보십시오. 항상 기본 및 액세스 토큰 대신 인증 된 이메일 ID를 추가하십시오.

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