How to programmatically import Google Drive media (Photos/Videos) to Google Photos?

489 views
Skip to first unread message

maarofi

unread,
Apr 5, 2022, 5:42:01 PM4/5/22
to Google Apps Script Community
Greetings,

I hope you are having a great day. I am working on building an automation service that takes a file from Google Drive (based on file ID/URL) and import it to Google Photos. Please have a look at this video that does exactly what I want to implement programmatically. 

Using Google Apps Script, I can accomplish this using GPhotosApp as following:
  • Get the file ID, grab its blob and send the blob to google photos (I have already implemented this - but it doesn't fulfil my requirements)
Since I want to integrate the solution into an existing software which is hosted on my private server, I can not use Google Apps Scripts in this case, rather would rely on Google Drive & Google Photos APIs.

The current approach I am thinking to implement has the following workflow: 
  1. Locate file (publicly shared file with view access) on the users' Google Drive using get file endpoint
  2. Get the content of the file (Facing problem here - described below)
  3. Create a new file in users' Google Photos using upload_media endpoint of Photos API
  4. Get URL of the newly created Google Photos file (Facing problem here - described below)

Currently, I do not have any working code that I can share because I am not sure if the current approach I came up with is actually going to work? Which is why I have these following queries to understand: 

  1. Do Google Photos API has a Node Js SDK ? Just like Google Drive V2 API has. 
  2. When hitting Google Drive file get endpoint I get back the file metadata (file id, url, mime type, etc), and not the actual content of that file. On the documentation page, they say " alt=media " would get you the file content but while trying the api call (on the documentation page), I only see " json (default) in alt parameter value  ". So, how can I get the publicly available file content form users' Google Drive?
  3. As demonstrated in the video, almost 900 MB file is imported instantly into Google Photos. How long would it take the file to imported in Google Photos programmatically? Does this depend on file size? For reference, file sizes can range from 2MBs - 10GBs.
  4. Lastly, how can I get the URL of media I just upload in Google Photos?
Sorry if I am not descriptive but I really would appreciate your response on this. If you need further clarification, I would love to respond back with more details. 

Stay blessed. 

Clark Lind

unread,
Apr 6, 2022, 11:48:24 PM4/6/22
to Google Apps Script Community
Hello, 
You might be able to use the following library from Tanaike:  https://github.com/tanaikech/GPhotoApp
or get some ideas from it.

maarofi

unread,
Apr 7, 2022, 6:08:02 PM4/7/22
to Google Apps Script Community
Thanks for responding and your suggestion. 

I already used it and attached the issues related to it in my question above. In fact, this throws "Exceeded File Size Limit" when I create to get blob of a video file when larger than 24 mb. 

Also, I am looking for a solution that uses Google Drive & Google Photos V2 API and not apps script. 

Clark Lind

unread,
Apr 8, 2022, 8:58:06 AM4/8/22
to Google Apps Script Community
My apologies... I obviously didn't read your first post very closely!  
This code may give you come ideas: https://github.com/roopakv/google-photos
Reply all
Reply to author
Forward
0 new messages