2013-01-16 1 views
3
public ContactFeed retrieveContacts(ContactsService service, 
            Credential credential) throws Exception { 

    URL url = new URL("https://www.google.com/m8/feeds/profiles/domain/my.domain.com/full"); 

    service.setOAuth2Credentials(credential); 
    service.useSsl(); 
    service.setHeader("GData-Version", "3.0"); 

    ContactFeed contactFeed = new ContactFeed(); 

    do { 
     ContactFeed feedResult = service.getFeed(url, ContactFeed.class); 
     contactFeed.getEntries().addAll(feedResult.getEntries()); 

     if (feedResult.getNextLink() != null && feedResult.getNextLink().getHref() != null 
       && !feedResult.getNextLink().getHref().isEmpty()) { 
      url = new URL(feedResult.getNextLink().getHref()); 
     } else { 
      url = null; 
     } 
    } while (url != null); 

    return contactFeed; 
} 

이것은 프로파일을 검색하기위한 코드입니다. 이 라인을Google Apps Profiles API : java.lang.NullPointerException : No 인증 헤더 정보

ContactFeed feedResult = service.getFeed(query, ContactFeed.class); 

를 실행하는 경우는 java.lang.NullPointerException이 제공되지 않습니다 : 없음 인증 헤더 정보를 오류가 발생했습니다.

Google 사이트 도구, Google 드라이브, Google Apps 프로비저닝, Google 이메일 설정이 OAuth2와 잘 작동합니다. 그러나 OAuth2가 포함 된 Google Apps 프로필은 을 제공합니다. java.lang.NullPointerException : 인증 헤더 정보가 없습니다.. 인터넷 서핑을했는데, 벌레라고 했어? AccessToken을 수동으로 헤더에 전달하는 것뿐입니다. 어쨌든이 작업을 할 수 있습니까? 왜냐하면 나는 이것을 Cron Job에서 실행하기 위해 사용하고 있으며 OAuth2 서비스 계정을 사용하고 있습니다.

====

편집 :

service.setHeader("GData-Version", "3.0"); 
service.setUserCredentials(myusername, mypassword); 

이 그냥 완벽하게 작동합니다

내가 이런 설정 헤더를-무력했습니다. service.setOAuth2Credentials()는 내부적으로 버그가있는 것 같습니다.

+0

문제를 해결 했습니까? 그렇다면 솔루션을 공유하십시오. 감사 –

답변

4

service.setOAuth2Credentials()가 새로운 Google 자격증 명 (P12File로 빌드)을 구축하지 못하는 이유를 발견했습니다.

그것은 당신이 P12File와 구글 자격 증명을 빌드하는 경우 REFRESH 토큰는 내부적으로 구글 사이트, 구글 드라이브 등의 다른 서비스 ... 같은

, 그냥이 추가되지 service.setOAuth2Credentials()가 않기 때문이다 Google 자격증 명을 작성한 후

googleCredential.refreshToken(); 

나는 ContactsService.setOAuth2Credentials() 버그입니다.

0

인증에 SecureSociale를 사용하는 동안이 문제가 발생했습니다.

필자의 경우이 문제는 SecureSociale의 구성에 정의 된 범위와 관련이있었습니다.

주어진 토큰에 올바른 범위를 사용하고 있는지 확인하는 것을 잊지 마십시오.