Create a shortcut file to content stored by your app Stay organized with collections Save and categorize content based on your preferences.
Third-party shortcuts in Google Drive are metadata-only files that link toother files on external, third-party owned, storage systems. These shortcuts actas reference links to the "content" files stored by an application outside ofDrive, usually in a different datastore or cloud storage system.
To create a third-party shortcut, use thefiles.create method ofthe Google Drive API and set the MIME type toapplication/vnd.google-apps.drive-sdk. Don't upload any content when creatingthe file. For more information, seeGoogle Workspaceand Google Drive supported MIMEtypes.
You cannot upload or download third-party shortcuts.
Note: If you're using the older Drive API v2, you can find code samples inGitHub. Learnhow tomigrate to Drive API v3.The following code samples show how to create a third-party shortcut using aclient library:
Java
importcom.google.api.client.googleapis.json.GoogleJsonResponseException;importcom.google.api.client.http.HttpRequestInitializer;importcom.google.api.client.http.javanet.NetHttpTransport;importcom.google.api.client.json.gson.GsonFactory;importcom.google.api.services.drive.Drive;importcom.google.api.services.drive.DriveScopes;importcom.google.api.services.drive.model.File;importcom.google.auth.http.HttpCredentialsAdapter;importcom.google.auth.oauth2.GoogleCredentials;importjava.io.IOException;importjava.util.Arrays;/* Class to demonstrate Drive's create shortcut use-case */publicclassCreateShortcut{/** * Creates shortcut for file. * * @throws IOException if service account credentials file not found. */publicstaticStringcreateShortcut()throwsIOException{/* Load pre-authorized user credentials from the environment. TODO(developer) - See https://developers.google.com/identity for guides on implementing OAuth2 for your application.*/GoogleCredentialscredentials=GoogleCredentials.getApplicationDefault().createScoped(Arrays.asList(DriveScopes.DRIVE_FILE));HttpRequestInitializerrequestInitializer=newHttpCredentialsAdapter(credentials);// Build a new authorized API client service.Driveservice=newDrive.Builder(newNetHttpTransport(),GsonFactory.getDefaultInstance(),requestInitializer).setApplicationName("Drive samples").build();try{// Create Shortcut for file.FilefileMetadata=newFile();fileMetadata.setName("Project plan");fileMetadata.setMimeType("application/vnd.google-apps.drive-sdk");Filefile=service.files().create(fileMetadata).setFields("id").execute();System.out.println("File ID: "+file.getId());returnfile.getId();}catch(GoogleJsonResponseExceptione){// TODO(developer) - handle error appropriatelySystem.err.println("Unable to create shortcut: "+e.getDetails());throwe;}}}
Python
importgoogle.authfromgoogleapiclient.discoveryimportbuildfromgoogleapiclient.errorsimportHttpErrordefcreate_shortcut():"""Create a third party shortcut Load pre-authorized user credentials from the environment. TODO(developer) - See https://developers.google.com/identity for guides on implementing OAuth2 for the application. """creds,_=google.auth.default()try:# create drive api clientservice=build("drive","v3",credentials=creds)file_metadata={"name":"Project plan","mimeType":"application/vnd.google-apps.drive-sdk",}# pylint: disable=maybe-no-memberfile=service.files().create(body=file_metadata,fields="id").execute()print(f'File ID:{file.get("id")}')exceptHttpErroraserror:print(f"An error occurred:{error}")returnfile.get("id")if__name__=="__main__":create_shortcut()
PHP
<?phpuse Google\Client;use Google\Service\Drive;use Google\Service\Drive\DriveFile;function createShortcut(){ try { $client = new Client(); $client->useApplicationDefaultCredentials(); $client->addScope(Drive::DRIVE); $driveService = new Drive($client); $fileMetadata = new DriveFile(array( 'name' => 'Project plan', 'mimeType' => 'application/vnd.google-apps.drive-sdk')); $file = $driveService->files->create($fileMetadata, array( 'fields' => 'id')); printf("File ID: %s\n", $file->id); return $file->id; } catch(Exception $e) { echo "Error Message: ".$e; }}
.NET
usingGoogle.Apis.Auth.OAuth2;usingGoogle.Apis.Drive.v3;usingGoogle.Apis.Services;namespaceDriveV3Snippets{// Class to demonstrate Drive's create shortcut use-casepublicclassCreateShortcut{/// <summary>/// Create a third party shortcut./// </summary>/// <returns>newly created shortcut file id, null otherwise.</returns>publicstaticstringDriveCreateShortcut(){try{/* Load pre-authorized user credentials from the environment. TODO(developer) - See https://developers.google.com/identity for guides on implementing OAuth2 for your application. */GoogleCredentialcredential=GoogleCredential.GetApplicationDefault().CreateScoped(DriveService.Scope.Drive);// Create Drive API service.varservice=newDriveService(newBaseClientService.Initializer{HttpClientInitializer=credential,ApplicationName="Drive API Snippets"});// Create Shortcut for file.varfileMetadata=newGoogle.Apis.Drive.v3.Data.File(){Name="Project plan",MimeType="application/vnd.google-apps.drive-sdk"};varrequest=service.Files.Create(fileMetadata);request.Fields="id";varfile=request.Execute();// Prints the shortcut file id.Console.WriteLine("File ID: "+file.Id);returnfile.Id;}catch(Exceptione){// TODO(developer) - handle error appropriatelyif(eisAggregateException){Console.WriteLine("Credential Not found");}else{throw;}}returnnull;}}}
Node.js
import{GoogleAuth}from'google-auth-library';import{google}from'googleapis';/** * Creates a shortcut to a third-party resource. * @return {Promise<string|null|undefined>} The shortcut ID. */asyncfunctioncreateShortcut(){// Authenticate with Google and get an authorized client.// TODO (developer): Use an appropriate auth mechanism for your app.constauth=newGoogleAuth({scopes:'https://www.googleapis.com/auth/drive',});// Create a new Drive API client (v3).constservice=google.drive({version:'v3',auth});// The metadata for the new shortcut.constfileMetadata={name:'Project plan',mimeType:'application/vnd.google-apps.drive-sdk',};// Create the new shortcut.constfile=awaitservice.files.create({requestBody:fileMetadata,fields:'id',});// Print the ID of the new shortcut.console.log('File Id:',file.data.id);returnfile.data.id;}
How third-party shortcuts work
When you create a third-party shortcut using thefiles.create method, it usesaPOST request to insert the metadata and create a shortcut to your app'scontent:
POST https://www.googleapis.com/drive/v3/filesAuthorization:AUTHORIZATION_HEADER{ "title": "FILE_TITLE", "mimeType": "application/vnd.google-apps.drive-sdk"}When the third-party shortcut is clicked, the user is redirected to the externalsite where the file is housed. The Drive file ID is contained inthestate parameter. For moreinformation, seeHandle an Open URL for app-specificdocuments.
The third-party app or website is then responsible for matching the file ID inthestate parameter to the content housed within their system.
Add custom thumbnails and indexable text
To increase the discoverability of files associated with third-party shortcuts,you can upload both thumbnail images and indexable text when inserting ormodifying the file metadata. For more information, seeManage file metadata.
Related topics
- Create a shortcut to a Drive file
- Configure a Drive UI integration
- Google Workspace and Google Drive supported MIME types
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-11 UTC.