How Google drive third party shortcuts work

Viewed 306

I was reading about third party shortcuts in Google Drive and able to create a file in Google Drive with the sample payload mentioned in the link.

var fileMetadata = new File()
{
    Name = "Project plan",
    MimeType = "application/vnd.google-apps.drive-sdk"
};
var request = driveService.Files.Create(fileMetadata);
request.Fields = "id";
var file = request.Execute();
Console.WriteLine("File ID: " + file.Id);

What I am not able to get is where can I set the external file URL here? Or how does it even work?

1 Answers

Answer

It is up to the third-party to handle the redirect to the relevant file for which a shortcut points to. This is done with the Google Drive File ID.

More Information:

Google Drive shortcuts are used to link a file, the contents of which are stored elsewhere than on Drive, such as a third party web app. This isn't done through links, as Drive shortcuts contain no content and are made using the file metadata endpoint.

When you make a Third-party shortcut using the Files.Create method as you show above, the indicative information of the fact it is a shortcut is by the application/vnd.google-apps.drive-sdk mimeType, using the POST URL for inserting file metadata:

POST https://www.googleapis.com/drive/v3/files
Authorization: <AUTHORIZATION HEADER>

{
  "title": "File's title",
  "description": "File's description",
  "mimeType": "application/vnd.google-apps.drive-sdk"
}

When the shortcut is clicked, you will then get redirected to the third party web site from which the file was created - the Google Drive File ID is contained inside the ?state query parameter, as per the documentation on Open Files.

The important thing to know is that it is completely up to the third-party app/website to use Google Drive File ID in the ?state parameter to match the file and content they have stored.

References:

Related