3

我需要为我的 android 应用程序实现 google 联系人 api。但到目前为止,我还没有找到任何关于 android 的参考资料。我为 java 找到了一个:https ://developers.google.com/google-apps/contacts/v3/

但是当我使用这段代码时:

ContactsService myService = new ContactsService("<var>YOUR_APPLICATION_NAME</var>");

我收到一个名为“exceptionInInitializerError”的运行时错误。

我已经在这里这里看过,但没有得到如何初始化“ContactsService”对象的特定解决方案。

那么你们中的任何人都可以为我提供一个指南,告诉我如何在我的应用程序中实现谷歌联系人 API 吗?

4

1 回答 1

0

请尝试此代码,它可能对您有所帮助

    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");
        }
    }
}
于 2015-02-05T09:32:43.693 回答