2

I need to implement google contact api for my android app. But I did not found any reference for android so far. I have found one for java: https://developers.google.com/google-apps/contacts/v3/

but when I use this code:

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

I get a runtime error called "exceptionInInitializerError".

I have already looked here and here but not getting specefic solution that how can I initialize a "ContactsService" object.

So can any of you kindly provide me a guideline that how can I implement the google contact api in my app?

Community
  • 1
  • 1
shaonAshraf
  • 1,107
  • 1
  • 11
  • 21

1 Answers1

0

Please try this code it may help you

    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");
        }
    }
}
Rahul Pareta
  • 786
  • 6
  • 18