首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google contact api for android

Google contact api for android
EN

Stack Overflow用户
提问于 2013-09-22 21:52:43
回答 1查看 833关注 0票数 3

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

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

代码语言:javascript
复制
ContactsService myService = new ContactsService("<var>YOUR_APPLICATION_NAME</var>");

我得到一个名为"exceptionInInitializerError“的运行时错误。

我已经看过herehere了,但没有得到如何初始化"ContactsService“对象的具体解决方案。

所以你们谁能给我提供一个指南,告诉我如何在我的应用程序中实现google contact api?

EN

回答 1

Stack Overflow用户

发布于 2015-02-05 17:32:44

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

代码语言:javascript
复制
    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");
        }
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18944569

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档