我的Google Contacts API v3出現問題。我在下面說明了我所做的步驟。Google Contacts API v3,JAVA GET ALL CONTACT「contactFeed.getEntries()is empty」!
- 通過Google的控制檯創建client_id,file.p12。
實現身份驗證機制:
公共ContactsExample(){
File p12 = new File("exampleContacts.p12"); HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); GoogleCredential credential = new GoogleCredential.Builder() .setTransport(httpTransport) .setJsonFactory(JacksonFactory.getDefaultInstance()) .setServiceAccountId("[email protected]") .setServiceAccountPrivateKeyFromP12File(p12) .setServiceAccountScopes(Collections.singleton("https://www.google.com/m8/feeds/")) .build(); if (!credential.refreshToken()) { throw new RuntimeException("Failed OAuth to refresh the token"); } service.setOAuth2Credentials(credential); printAllContacts(service);
}
檢索我的聯繫人:
查詢cQuery =新的查詢(新的Java .net.URL(「https://www.google.com/m8/feeds/contacts/default/full」)); cQuery.setMaxResults(10);
ContactFeed feed = service.getFeed(cQuery, ContactFeed.class);
for (ContactEntry contact : feed.getEntries()) {
System.out.println("name: " + contact.getTitle().getPlainText());
}
當我執行ContactFeed進料= service.getFeed(cQuery,ContactFeed.class);,則此方法返回一個空列表。什麼不見了?
我會補充說,我已經在客戶端使用api JavaScript v3執行了相同的過程,並且它完美地工作。
謝謝!
您的代碼中並不清楚,因此,請仔細檢查:您是否在考慮使用隨時可用的庫,如https://github.com/google/gdata-java-client或http:// cloudsponge .com/contact-importers/gmail? –
我使用第一個:github.com/google/gdata-java-client – emilio86