【问题标题】:Google contact api for android适用于 Android 的 Google 联系人 API
【发布时间】:2013-09-22 13:52:42
【问题描述】:
我需要为我的 android 应用程序实现 google contact 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 联系人 API 吗?
【问题讨论】:
标签:
java
android
android-contacts
google-contacts-api
【解决方案1】:
请试试这个代码,它可能对你有帮助
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");
}
}
}