我需要为我的android应用程序实现谷歌联系人api。但到目前为止,我还没有找到任何android的参考资料。我已经为java找到了一个:https://developers.google.com/google-apps/contacts/v3/。
但是当我使用这段代码时:
ContactsService myService = new ContactsService("<var>YOUR_APPLICATION_NAME</var>");我得到一个名为"exceptionInInitializerError“的运行时错误。
我已经看过here和here了,但没有得到如何初始化"ContactsService“对象的具体解决方案。
所以你们谁能给我提供一个指南,告诉我如何在我的应用程序中实现google contact api?
发布于 2015-02-05 17:32:44
请尝试此代码,它可能会对您有所帮助
public void printAllContacts()throws ServiceException, IOException {
ContactsService myService = null;
myService = new ContactsService(accessToken);//add here your access token
myService.setAuthSubToken(accessToken);//add here your access token
URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/default/full?max-results=5000");
ContactFeed resultFeed = myService.getFeed(feedUrl, ContactFeed.class);
for (int i = 0; i < resultFeed.getEntries().size(); i++) {
ContactEntry entry = resultFeed.getEntries().get(i);
if (entry.hasName()) {
Name name = entry.getName();
if (name.hasFullName()) {
String fullNameToDisplay = name.getFullName().getValue();
if (name.getFullName().hasYomi()) {
fullNameToDisplay += "("
+ name.getFullName().getYomi() + ")";
}
System.out.println(fullNameToDisplay);
}
for (Email email : entry.getEmailAddresses()) {
System.out.println(email.getAddress());
}
Link photoLink = entry.getContactPhotoLink();
String photoLinkHref = photoLink.getHref();
System.out.println("Photo Link:" + photoLinkHref+"\n");
}
}
}https://stackoverflow.com/questions/18944569
复制相似问题