Вот код, над которым я работал:
public String getGoogleContact(String queryStr) throws
AuthenticationException, MalformedURLException, IOException,
ServiceException, GeneralSecurityException{
String emailAddress = "[email protected]";
JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
String path = "src/main/resources/key.p12";
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId(emailAddress)
.setServiceAccountPrivateKeyFromP12File(new java.io.File(path))
.setServiceAccountScopes(Collections.singleton("https://www.google.com/m8/feeds"))
.setServiceAccountUser("[email protected]").build();
ContactsService service = new ContactsService("MYAPP");
service.setOAuth2Credentials(credential);
Query myQuery = new Query( new URL("https://www.google.com/m8/feeds/contacts/default/full"));
myQuery.setFullTextQuery(queryStr);
ContactFeed resultFeed = service.query(myQuery, ContactFeed.class);
String result = "";
for (ContactEntry entry : resultFeed.getEntries()) {
result += entry.getTitle().getPlainText();
}
return result;
}
И я получаю следующее исключение:
java.lang.NullPointerException: нет информации заголовка аутентификации в com.google.gdata.util.AuthenticationException.initFromAuthHeader(AuthenticationException.java:96) ~[core-1.47.1.jar:na] в com.google.gdata.util. AuthenticationException.(AuthenticationException.java:67) ~[core-1.47.1.jar:na] в com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:608) ~[core-1.47.1. jar:na] на com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:564) ~[core-1.47.1.jar:na] на com.google.gdata.client.http.HttpGDataRequest. checkResponse(HttpGDataRequest.java:560) ~[core-1.47.1.jar:na] в com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:538) ~[core-1.47.1.jar :na] в com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:536) ~[core-1.47.1.jar:na] в com.google.gdata.client.Service.getFeed(Service .java:1135) ~[core-1.47.1.jar:na] в com.google.gdata.client.Servic e.getFeed(Service.java:1077) ~[core-1.47.1.jar:na] в com.google.gdata.client.GoogleService.getFeed(GoogleService.java:676) ~[core-1.47.1.jar :na] в com.google.gdata.client.Service.query(Service.java:1237) ~[core-1.47.1.jar:na] в com.google.gdata.client.Service.query(Service.java :1178) ~[ядро-1.47.1.jar: нет]
Пожалуйста помоги!