2013-09-22 91 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"); 
     } 
    } 
}