Search code examples
androidgoogle-drive-apigoogle-drive-android-api

Get file from Google Drive via shared link


I'm making something like online journal app, that will download "journal file" from Google Drive (via shared link) once and will update that file if it changes. Please, can anyone point me to some guides how to do it. I already tried to pin file from drive, but I don't really understand what to do next..


Solution

  • Downloading Files from Google Drive:

    To download a Google Drive file via link, try this (from this tutorial):

    https://drive.google.com/uc?export=download&id=FILE_ID

    Just replace the FILE_ID with the original fileID found in the Drive URL.

    Additonal notes:

    You can download files using the DRIVE REST API

    To download files, you make an authorized HTTP GET request to the file's resource URL and include the query parameter alt=media. For example:

    GET https://www.googleapis.com/drive/v3/files/0B9jNhSvVjoIVM3dKcGRKRmVIOVU?alt=media
    Authorization: Bearer ya29.AHESVbXTUv5mHMo3RYfmS1YJonjzzdTOFZwvyOAUVhrs
    

    Downloading the file requires the user to have at least read access. Additionally, your app must be authorized with a scope that allows reading of file content. For example, an app using the drive.readonly.metadata scope would not be authorized to download the file contents. Users with edit permission may restrict downloading by read-only users by setting the viewersCanCopyContent field to true.

    Updating files in Google Drive

    Make an HTTP Request to Google Drive using PATCH. The PATCH method requests that a set of changes described in the request entity be applied to the resource identified by the Request- URI. Things to take note of are:

    1. Parameters
    2. Authorization
    3. Request Body