Newbies gymtech Posted May 6, 2009 Newbies Posted May 6, 2009 Just wondering if any has anyone has gotten a contacts table to sync with google/gmail contacts successfully.
Lev Leviev Posted September 19, 2010 Posted September 19, 2010 Bump I feel silly doing csv imports and scripting functions to correct them when my phone can sync with my google accounts automatically. Lev
fseipel Posted September 20, 2010 Posted September 20, 2010 (edited) While it won't directly sync, you should be able to achieve syncing automatically by using the the Google Data API Link The API can be called with Scriptmaster to get and update the contact list. Since the API includes a java library this will be rather trivial. Below code is a working sample to get the contact list using Google data API and return it as a string; I would have uploaded it but the FM file was too large. It assumes an input variable 'email_address', and 'password' e.g. [email protected], yourpassword. It would be interesting to see an FM DB sample that does similar with Google Calendars. JARs required are Gdata-Client-1.0, GData-Contacts-3.0, GData-Core-1.0, Google-Collect-1.0-Rc1, and Jsr 305.jar. Latter two available from: Link ; remainder are in Link i.e. gdata.java-1.41.5.zip in gdata/java/lib folder once unzipped (i.e. in the API) // Note well, for Scriptmaster, must have Jar libraries google-collect and jsr305.jar ex http://code.google.com/p/gdata-java-client/source/browse/#svn/trunk/java/deps // Must also load the relevant Google data API JARs (Client, Contacts, Core) // Below derived from https://groups.google.com/group/google-appengine-java/browse_thread/thread/48901205e2e073f8 and adapter for ScriptMaster import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import com.google.gdata.client.Query; import com.google.gdata.client.contacts.ContactsService; import com.google.gdata.data.contacts.ContactEntry; import com.google.gdata.data.contacts.ContactFeed; import com.google.gdata.data.extensions.Email; import com.google.gdata.util.AuthenticationException; import com.google.gdata.util.ServiceException; public class GmailContacts { public static List getConatacts(String email, String password) throws IOException, ServiceException { ContactsService service = new ContactsService( "Google-contactsExampleApp-3"); service.setUserCredentials(email, password); URL url = new URL( "http://www.google.com/m8/feeds/contacts/"+email+"/thin"); Query myQuery = new Query(url); myQuery.setMaxResults(1000); ContactFeed resultFeed = service.query(myQuery, ContactFeed.class); List contactList = new ArrayList(); for (ContactEntry entry : resultFeed.getEntries()) { List emailList = entry.getEmailAddresses(); for (Iterator iterator = emailList.iterator(); iterator.hasNext() { Email emailObj = (Email) iterator.next(); contactList.add(new Contact(emailObj.getAddress(), entry .getTitle().getPlainText() == null ? "" : entry .getTitle().getPlainText())); // String name = entry.getName()!= // null?entry.getName().toString():""; // System.out.println(entry.getTitle().getPlainText()+" //"+entry.getNickname()+" "+entry.getShortName()+" "+email.getDisplayName()+" //"+email.getAddress()); } } return contactList; } } public class Contact { private String email; private String title; public Contact(String email, String title) { super(); this.email = email; this.title = title; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } } String the_contacts =""; // String to store contact list with name separated by e-mail address with Pipe symbol List contList = GmailContacts.getConatacts(email_address, password); for (Iterator iterator = contList.iterator(); iterator.hasNext(): { Contact contact = (Contact) iterator.next(); the_contacts=the_contacts +contact.getTitle() + "|" + contact.getEmail() + "n"; // Append names and e-mail addresses to String to be returned to FM } return the_contacts; Edited September 20, 2010 by Guest
Lev Leviev Posted October 29, 2010 Posted October 29, 2010 Thank you!! This looks like exactly what I need. I just tried running it in Scripmaster and got this error: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script1.groovy: 48: unexpected token: return @ line 48, column 1. return contactList; ^ 1 error Any thoughts? Best, Lev
fseipel Posted October 30, 2010 Posted October 30, 2010 (edited) I'm not sure why you received an error; did you load the JAR files? I posted an example here Link If you do some further work on this for syncing, please post it. I would have just attached example, but with the JARs, it exceeds the length limit for the forum. Edited October 30, 2010 by Guest
Lev Leviev Posted October 31, 2010 Posted October 31, 2010 This works!! Thanks so much. I tried pasting the script you posted into a new script in your example file and it's still giving me the same errors. So, I don't think it's the JARs not loading. I also ran into a couple of other small errors: 1) The script "Google Calendar Example; gets all events without query parameter" returns this error: groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.getPlainText() is applicable for argument types: () values: [] 2) "Add contact to Google Contacts Tested" didn't seem to add the custom "favorite flower" field. But overall, this is fantastic and I'm excited to start working with it! I will definitely post my results. Best, Lev
fseipel Posted November 1, 2010 Posted November 1, 2010 The script is adding the Extended Property 'favourite flower'; however, Extended Properties don't show up on the web interface to Google Contacts. If you want the 'Get Google Contacts List Works Fine based on Google code' to enumerate them, add a line such as this to return them: data_to_return = data_to_return + property.getName() + ": " + property.getValue(); Alternately you may want to return them to a separate output variable. This is a work-in-progress, the other script's error is due to the variable type not being a string; it needs a type conversion. I'm not returning all properties presently, all the println's go nowhere and should be changed to output to a variable if you want the corresponding property returned to FM, since println output is not returned in ScriptMaster. Thus you may need to make similar changes if you want/need Full Name, IM addresses, Groups,etc in FM. Perhaps formatting 'data_to_return' as CSV, saving it to a file, and importing back to FM would be a good way to sync? Import could be to a temporary table for processing, if there needs to be rules on whether FM or Google changes take precedence. System.out.println("Extended Properties:"); for (ExtendedProperty property entry.getExtendedProperties()) { if (property.getValue() != null) { data_to_return = data_to_return + property.getName() + ": " + property.getValue(); System.out.println(" " + property.getName() + "(value) = " + property.getValue()); } else if (property.getXmlBlob() != null) { System.out.println(" " + property.getName() + "(xmlBlob)= " + property.getXmlBlob().getBlob()); } Also, is there a way in ScriptMaster, to re-direct standard output to a string automatically?
John Sindelar Posted November 28, 2010 Posted November 28, 2010 FWIW, the January 2011 release of Zulu will synch FileMaker to Google Contacts. (Wednesday's release introduces this for Google Calendar). You can see the feature roadmap for Zulu here: http://www.seedcode.com/zulu/roadmap Hope it helps, John
Recommended Posts
This topic is 5110 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now