2013-09-22 168 views
3

我需要为我的android应用程序实现谷歌联系api。但到目前为止我还没有找到任何有关android的参考。我发现一个针对Java:https://developers.google.com/google-apps/contacts/v3/谷歌联系api为Android

但是当我使用此代码:

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

我会得到一个名为“的ExceptionInInitializerError”运行时错误。

我已经看了herehere,但没有得到specefic解决方案,我怎么能初始化一个“ContactsService”对象。

所以,你们可以向我提供一个指导方针,我如何在我的应用程序中实现谷歌联系人API?

+0

你收到这方面的任何解决方案? – Noundla

回答

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"); 
     } 
    } 
}