Closed knwpsk closed 4 months ago
It might be worth reading through the setup instructions as it may answer more of your questions.
As for setting this up on a work computer, I would ask your admin folks for a more robust business solution. This code has never been tested in an environment with a large number of users (I've tested it with five accounts with no problems). I literally wrote this so my wife and I could share contacts.
Brilliant, thanks flea Yes I'm reading thru the setup now. Are the matching contact IDs saved in the spreadsheet?
Answered my own question - I see the person ID in columns Z and AB in the master account tab on the spreadsheet.
Different question, but still "how it works": When I tinkered with this before (and tried some third-party sync apps), there was a weird thing. Google apparently updates the "updated date/time" in a contact, every time I get an email from, or a phone call from, that contact. This created some weird dynamics where there was nothing to sync, but the script/app tried to sync the contact anyway. Did you notice this too? Did you find a workaround? Or did Google fix it? etc. What field(s) do you use to determine which contact has been updated, and which is most recent?
I did notice it. I couldn't see any way Google distinguished between sending an email and actually changing a contact. I thought about checking to see if there were any changes before updating, but that would have to be done for every contact where the time stamp had changed. That would just make the script take longer to run and bump up against the script time limits. I just didn't see a reason to just not update the contact. Plus, if I didn't update the contact, I'd have to deal with different time stamps on the sync'd contact - I just didn't want that headache when the script was working already.
yeah that's about where my thoughts ended up, too I wish we could get Google to do the update timestamp more sensibly/usefully.
You use the .sync.text file to store an iterator ID, right? Did you consider using the script User Properties for that?
What is the purpose of the named tabs in the spreadsheet? I'm syncing two accounts now, and both have tabs in the file, and both of those tabs are empty.
The text file is for storing the sync token.
Each sheet is a temporary holding space for contacts which need to be sync'd. If they sheets are empty, no contacts need to be sync'd.
Google puts quotas on how long and how often scripts can run. If hundreds of contacts are being sync'd (e.g., during setup), the sheets will store those contacts. The script handles the quotas by using the sync token for the script to identify where the previous run left off. Version 1 of the script didn't use the sheets for temporary holding - when sync'ing lots of contacts or more than two accounts, the script took a very long time to finish the sync because it was having to check every contact for sync'ing every time it ran. Version 2 is much faster and more reliable because even if it encounters an error, the spreadsheet still contains the contacts which need to be sync'd and the sync token isn't updated until after they are sync'd.
The script will have issues on occasion (for example, if one person updates a contact and another user deletes it, the script wont' know what to do because it can't update the deleted contact). The user who deleted the contact will get an email informing them of the situation.
Additionally, Google will screw up the sync tokens on occasion (I don't know why) and an email will be sent to the alert email. If there is a sync token error, the script will reset and try again on the next run - no data will be lost. An occasional sync token error email is fine (I get one every couple of days). It's not a problem unless you are getting a sync token error on every run (which you really shouldn't unless there is a problem with your setup).
The script isn't perfect, and every once in awhile I'll notice it resurrect some old data (like labels or organizations) out of nowhere (none of the users will have a contact with a certain label after it has been removed, but it will somehow be added back in hours or days later). However, it has never lost any of my data. This particular problem hasn't proven to be that much of a pain, so I haven't chosen to invest the time to investigate why it is happening. Given the time frame in which it happens, it may not be a coding issue and might require me to have a better understanding of how Google handles contacts.
OK thanks for all of that.
I've got another script which runs monthly, and saves all of my contacts to a sheet for backup. Maybe I should put it in a repo for sharing...
More the merrier!
Everyone who comes here should please go to the "feature request" linked below and +1 it. It's a ticket for google to fix the issue where contact.updateTime is updated when there has been no user interaction with a contact.
edit: going to put this in its own ticket.
Flea, an edge case here: In my "client" account I merged two contacts into one. They were nearly identical, but one had the company name and the other didn't, and I think they had a slightly different set of Groups assigned. That merge didn't seem to do anything when the next sync ran. In my "master" account, I still have the two original contacts for that person, and the values didn't seem to change in either one.
I would have tentatively expected the script to: a. not really recognize a "merge" (because how would it?) b. but to recognize that one contact was deleted, and the other contact was updated But neither seemed to happen.
Thoughts? Something to improve?
p.s. if you'd like to collaborate directly, I put an email address in my profile
Flea, How does the script determine which Contacts have been updated recently? I'm looking at SyncContacts, and it calls GetUpdatedContacts(). But GetUpdatedContacts seems to query "all contacts that belong to me" with people.connections.list(); and I can't see anywhere that it filters them according to updated date (etc). How/where does that filtering happen?
Thank you
Take a look at sync tokens. https://developers.google.com/people/api/rest/v1/contactGroups/list
Yes I'll go read the code. :)
Meanwhile, before I attempt to run this in my work (Gsuite) account, I need to know how it works, and be able to defend using it.
So, could you update the readme to give just a high-level overview of what it does? e.g.
p.s. THANK YOU FOR DOING THIS AND FOR SHARING IT!