📎 Webclip
How to download files from Google Drive using Elixir
The post explains a small workflow for reading a CSV file from Google Drive in Elixir. It starts by setting up a service account, saving the JSON credentials in the project, and sharing the target Drive folder with the service account email.
Reading notes#
- create a service account in Google Developer Console and save the JSON credentials file in the Elixir project
- give the service account access to the domain accounts if needed, though the post says this step may not be necessary
- share the Drive folder that contains the files with the service account email
- add
google_api_driveandgothtomix.exs - configure
gothinconfig.exsto read the JSON credentials file - request a token for the Google Drive scope with
Goth.Token.for_scope("https://www.googleapis.com/auth/drive") - create a Drive connection with the token
- list files with
drive_files_list/2usingincludeItemsFromAllDrives,supportsAllDrives, andcorpora: "allDrives" - filter the returned files for
text/csv, take the first one, and keep itsidandname - fetch the file body with
drive_files_get/4usingmimeType: "text/csv",alt: "media", anddecode: false - the final result is the downloaded body of the CSV file
