我正在尝试通过Google Client API 1.47.1的jar示例获取所有联系人
我刚刚创建了一个Auth类,以获得新的ContactsService。
public class Auth {
public static class ProfilesManager {
private String domain;
private String adminEmail;
private int batchSize = 100;
private List<ContactEntry> profiles;
private ContactsService myService;
public ProfilesManager(String consumerKey, String consumerSecret, String adminEmail)
throws OAuthException {
this.adminEmail = adminEmail;
this.domain = adminEmail.substring(adminEmail.indexOf('@') + 1);
GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey(consumerKey);
oauthParameters.setOAuthConsumerSecret(consumerSecret);
this.myService = new ContactsService("GoogleInc-UnshareProfiles-1");
this.myService.setOAuthCredentials(oauthParameters, new OAuthHmacSha1Signer());
}
public int getBatchSize() {
return this.batchSize;
}
public void setBatchSize(int value) {
this.batchSize = value;
}
public List<ContactEntry> getProfiles() {
return this.profiles;
}
public void getAllProfiles() throws IOException, ServiceException {
ArrayList<ContactEntry> profiles = new ArrayList<ContactEntry>();
URL feedUrl =
new URL("https://www.google.com/m8/feeds/profiles/domain/" + this.domain
+ "/full?xoauth_requestor_id=" + this.adminEmail);
while (feedUrl != null) {
ContactFeed resultFeed = this.myService.getFeed(feedUrl, ContactFeed.class);
profiles.addAll(resultFeed.getEntries());
if (resultFeed.getNextLink() != null && resultFeed.getNextLink().getHref() != null
&& resultFeed.getNextLink().getHref().length() > 0) {
feedUrl = new URL(resultFeed.getNextLink().getHref());
} else {
feedUrl = null;
}
}
this.profiles = profiles;
}
}
}
但是在创建ContactsService的新实例时,此代码会生成异常:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/Maps
at com.google.gdata.wireformats.AltRegistry.<init>(AltRegistry.java:118)
at com.google.gdata.wireformats.AltRegistry.<init>(AltRegistry.java:100)
at com.google.gdata.client.Service.<clinit>(Service.java:555)
at google.Auth$ProfilesManager.<init>(Auth.java:43)
at main.Main.main(Main.java:16)