- available in Hex, the package can be installed
by adding
gdrive
to your list of dependencies inmix.exs
:
def deps do
[
{:gdrive, "~> 0.1.0"}
]
end
-
Create or select a project at Google Drive API enabler wizard. Click Continue. Click Go to credentials.
-
Select Other non-UI > Click Application data > Click No, I have not used. > Click Required credentials.
-
Input Service account name, Select Porject - Owner. Click next, Start download JSON automatically. Rename it to client_secret.json and move to config folder.
-
Click Manage service accounts > Edit service account > Click Enable G Suite domain wide delegation > Save.
-
Browse Google Drive > select any folder > share with service account id(like [email protected]).
-
Add to your
config.exs
file:
config :goth,
json: "./config/client_secret.json" |> File.read!
Gdrive wrap basic Files api with:
- create files
- create folder
- list
- get files
- upload files
- update, copy, delete file/folder
{status, file_info} = Gdrive.upload("/user/my_folder/file.txt", name: "first-file.txt")
You can make a request with Gdrive.Api.File
which support all params
# grab google token
{_, token} = Goth.Token.for_scope("https://www.googleapis.com/auth/drive,https://www.googleapis.com/auth/drive.file,https://www.googleapis.com/auth/drive.appdata")
# init new connection
connection = Connection.new(token)
# send request
{status, data} = Gdrive.Api.File.create(connection, name: "empty.txt", mimeType: "text/plain")