public void addContact(Contact c, String[] groups) { try { // Create the entry to insert ContactEntry contact = new ContactEntry(); Name name = new Name(); final String NO_YOMI = null; name.setFullName(new FullName(c.getName(), NO_YOMI)); name.setGivenName(new GivenName(c.getName(), NO_YOMI)); name.setFamilyName(new FamilyName(c.getSurname(), NO_YOMI)); contact.setName(name); Email primaryMail = new Email(); primaryMail.setAddress(c.getEmail()); primaryMail.setPrimary(true); contact.addEmailAddress(primaryMail); URL postUrl = new URL("https://www.google.com/m8/feeds/contacts/default/full"); try { myService.insert(postUrl, contact); } catch (IOException ex) { Logger.getLogger(ContactsHandlerImpl.class.getName()).log(Level.SEVERE, null, ex); } catch (ServiceException ex) { Logger.getLogger(ContactsHandlerImpl.class.getName()).log(Level.SEVERE, null, ex); } } catch (MalformedURLException ex) { Logger.getLogger(ContactsHandlerImpl.class.getName()).log(Level.SEVERE, null, ex); } }
public ContactsHandlerImpl(String user, String password, int cachelimit) throws AuthenticationException { myService = new ContactsService("kostaskar-testContacts-1"); myService.setUserCredentials(user, password); resetCacheLimit(cachelimit); }
public void importAllContacts() throws IOException, ServiceException { // import contacts setService(); URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/[email protected]/full"); Query myQuery = new Query(feedUrl); myQuery.setMaxResults(10); ContactFeed resultFeed = myService.query(myQuery, ContactFeed.class); // Print the results System.out.println(resultFeed.getTitle().getPlainText()); for (int i = 0; i < resultFeed.getEntries().size(); i++) { ContactEntry entry = resultFeed.getEntries().get(i); // Determine if this contact entry already exists in database (check Google ID): System.out.println(entry.getEtag()); System.out.println(entry.getId()); // if individual exists with Google ID, check to see if that invididual has all the emails // listed: // People tryPerosn = peopleRepo.findByPropertyValue("googleId", "googleId", entry.getId()); if (peopleRepo.findByPropertyValue("googleId", "googleId", entry.getEtag()) != null) { System.out.println( peopleRepo .findByPropertyValue("googleId", "googleId", entry.getId()) .getNodeId() .toString() + " He exists!"); } else { importContact(entry); } entry.getEmailAddresses(); } // If entry exists, check to see if entry }
public Contact[] getContacts() { if (cacheExpired() || numOfOperations == 0) { try { URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/default/full"); resultFeed = myService.getFeed(feedUrl, ContactFeed.class); } catch (IOException ex) { Logger.getLogger(ContactsHandlerImpl.class.getName()).log(Level.SEVERE, null, ex); } catch (ServiceException ex) { Logger.getLogger(ContactsHandlerImpl.class.getName()).log(Level.SEVERE, null, ex); } contacts = new Contact[resultFeed.getEntries().size()]; for (int i = 0; i < contacts.length; i++) { ContactEntry contact = resultFeed.getEntries().get(i); contacts[i] = new Contact(contact); } } return contacts; }
public void setService() throws AuthenticationException { myService = new ContactsService("exampleCo-exampleApp-1"); myService.setUserCredentials(user, pass); }
public void printAllContacts() throws ServiceException, IOException { // Request the feed setService(); URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/[email protected]/full"); Query myQuery = new Query(feedUrl); myQuery.setMaxResults(8); myQuery.setStringCustomParameter("group", "Business Contacts"); ContactFeed resultFeed = myService.query(myQuery, ContactFeed.class); // Print the results System.out.println(resultFeed.getTitle().getPlainText()); for (int i = 0; i < resultFeed.getEntries().size(); i++) { ContactEntry entry = resultFeed.getEntries().get(i); Name test = entry.getName(); FullName namee = test.getFullName(); People person = peopleRepo.save( new People(23, entry.getTitle().getPlainText(), entry.getTitle().getPlainText())); System.out.println(person.getNodeId().toString()); System.out.println("\t" + entry.getTitle().getPlainText()); System.out.println("Email addresses:"); for (com.google.gdata.data.extensions.Email email : entry.getEmailAddresses()) { System.out.print(" " + email.getAddress()); if (email.getRel() != null) { System.out.print(" rel:" + email.getRel()); } if (email.getLabel() != null) { System.out.print(" label:" + email.getLabel()); } if (email.getPrimary()) { System.out.print(" (primary) "); } System.out.print("\n"); } System.out.println("IM addresses:"); for (Im im : entry.getImAddresses()) { System.out.print(" " + im.getAddress()); if (im.getLabel() != null) { System.out.print(" label:" + im.getLabel()); } if (im.getRel() != null) { System.out.print(" rel:" + im.getRel()); } if (im.getProtocol() != null) { System.out.print(" protocol:" + im.getProtocol()); } if (im.getPrimary()) { System.out.print(" (primary) "); } System.out.print("\n"); } System.out.println("Groups:"); for (GroupMembershipInfo group : entry.getGroupMembershipInfos()) { String groupHref = group.getHref(); System.out.println(" Id: " + groupHref); } System.out.println("Extended Properties:"); for (ExtendedProperty property : entry.getExtendedProperties()) { if (property.getValue() != null) { System.out.println(" " + property.getName() + "(value) = " + property.getValue()); } else if (property.getXmlBlob() != null) { System.out.println( " " + property.getName() + "(xmlBlob)= " + property.getXmlBlob().getBlob()); } } String photoLink = entry.getContactPhotoLink().getHref(); System.out.println("Photo Link: " + photoLink); System.out.println("Contact's ETag: " + entry.getEtag()); } }