0

Right now I am running a script on a google sheet to sync contacts between two accounts.

When I am updating I am comparing current vs past data. The contact photos themselves are the same most of the time, with few changes, so I don't want to have to update hundreds of photos each time, which takes a while. Unfortunately I have been unable to find a way to effectively compare the previous photo to the current one.

Each time a contact has a photo uploaded to it you need to give it encoded data, which then google creates it at a given url. The urls for identical photos are different, and when comparing length etc of identical photos from two URLS the photo data doesn't match up. How can I tell if two photos are identical given two photo urls?

Example urls:

https://lh3.googleusercontent.com/-0oH1FBrea-M/YIHHfTH0ICI/AAAAAAAAAAA/YrYmrA92lLoyOf-eTNu8geyomhaEHGEsACOQCEAE/s100/photo.jpg

https://lh3.googleusercontent.com/-G7JfH_vmY3I/YJ2RRLUp0VI/AAAAAAAAAAA/XMDZ_LNXi709ofwRMmI9uLgUOZU7bMVmQCOQCEAE/s100/photo.jpg

Solution: What I ended up doing is storing the first contacts photo_url in the miscKeywords property on the Person object, since I wasn't using anything tied to that. When I went to update my contacts I pulled all the contacts that should match, and then compared the miscKeywords section to see if the url has updated or not.

  • About `The urls for identical photos are different, and when comparing length etc of identical photos from two URLS the photo data doesn't match up.` and `How can I tell if two photos are similar given two photo urls?`, do you want to compare whether 2 images are the same? Or, do you want to compare whether 2 images are the similar which is not the same? – Tanaike May 18 '21 at 22:58
  • @Tanaike Thank you, I meant identical. I used similar because the data when i encoded the photos didn't match up, so I was looking for something like https://github.com/mapbox/pixelmatch that I could compare the differences of pixels. Unfortunately that tool didn't work because the dimensions of the photos didn't line up when encoded. – David Westwood May 18 '21 at 23:49
  • Thank you for replying. When you want to check whether 2 images are the same, I think that the file size and the byte array can be used. But when I saw your 2 images, it seems that those images are not the same. In your sample 2 images, you want to retrieve the result that those images are not same? – Tanaike May 19 '21 at 00:12
  • Unless the links are taking us to different places they are the same photo. What makes you say they are different? – David Westwood May 19 '21 at 00:17
  • Thank you for replying. For example, when you check the file size of the both images of the URLs, those are different. How about this? – Tanaike May 19 '21 at 00:19
  • Thanks for that clarification. That's the issue I'm running into, I had a hard time explaining it. They both started out as the same file, but when uploaded as a google contact profile picture, each contact creates its own photo url, with different sizes. That is the crux of the problem. Because although the sizes are different they should be the same image. – David Westwood May 19 '21 at 00:31
  • Thank you for replying. From your replying, I understood that you said about the photos uploaded to Google Contacts. In this case, when I upload 2 same images to Google Contacts as the photo, and when I check both photos, the file size is the same. So unfortunately, I cannot replicate your situation. I apologize for this. Can I ask you about the detail flow for replicating your situation? – Tanaike May 19 '21 at 00:44
  • I am using the People API to pull the person data from a contact, which gives me the photo url. From there I am creating a new contact and using that photo with it. In order to update a contacts photo via the People API I have to give it an encoded image, which I do by creating a blob and encoding it to base64 using Utilities.base64EncodeWebSafe. – David Westwood May 19 '21 at 01:12
  • Thank you for replying. When I tested your flow, unfortunately, I cannot replicate your situation. I apologize for this. But, when I could replicate it, I would like to think of the solution and workaround. I deeply apologize I cannot resolve your issue soon. This is due to my poor skill. I deeply apologize for this again. – Tanaike May 19 '21 at 01:30
  • Hi there @DavidWestwood! In Drive API files you can access a property called `md5Checksum` that shows the checksum of the file. Would this approach be a valid resolution in your setup? – Jacques-Guzel Heron May 19 '21 at 06:35
  • Unfortunately not, since my files aren't on the drive api. I ended up doing a roundabout solution. I stored the original photo url in the contacts miscKewords attribute, and when I update I check if that photo url has changed. Thanks for the help! – David Westwood May 20 '21 at 20:14
  • I am glad that you found a solution for this situation. In order to better document this issue, could you please write an answer explaining your fix? – Jacques-Guzel Heron May 26 '21 at 13:29

0 Answers0