Google Drive의 서드 파티 바로가기는 서드 파티 소유의 외부 스토리지 시스템에 있는 다른 파일에 연결되는 메타데이터 전용 파일입니다. 이러한 바로가기는 Drive 외부의 애플리케이션(일반적으로 다른 데이터 스토어 또는 클라우드 스토리지 시스템)에 저장된 '콘텐츠' 파일에 대한 참조 링크 역할을 합니다.
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;}}}
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()
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;}}}
/** * Create a third party shortcut * @return{obj} shortcut Id * */asyncfunctioncreateShortcut(){// Get credentials and build service// TODO (developer) - Use appropriate auth mechanism for your appconst{GoogleAuth}=require('google-auth-library');const{google}=require('googleapis');constauth=newGoogleAuth({scopes:'https://www.googleapis.com/auth/drive',});constservice=google.drive({version:'v3',auth});constfileMetadata={name:'Project plan',mimeType:'application/vnd.google-apps.drive-sdk',};try{constfile=awaitservice.files.create({requestBody:fileMetadata,fields:'id',});console.log('File Id:',file.data.id);returnfile.data.id;}catch(err){// TODO(developer) - Handle errorthrowerr;}}
서드 파티 바로가기 작동 방식
files.create 메서드를 사용하여 서드 파티 바로가기를 만들면 POST 요청을 사용하여 메타데이터를 삽입하고 앱 콘텐츠의 바로가기를 만듭니다.
POST https://www.googleapis.com/drive/v3/files
Authorization: AUTHORIZATION_HEADER
{
"title": "FILE_TITLE",
"mimeType": "application/vnd.google-apps.drive-sdk"
}
서드 파티 바로가기를 클릭하면 파일이 저장된 외부 사이트로 리디렉션됩니다. Drive 파일 ID는 state 매개변수에 포함되어 있습니다. 자세한 내용은 앱별 문서의 Open URL 처리를 참고하세요.
그러면 서드 파티 앱 또는 웹사이트에서 state 매개변수의 파일 ID를 시스템 내에 있는 콘텐츠와 일치시켜야 합니다.
맞춤 썸네일 및 색인이 생성 가능한 텍스트 추가
서드 파티 바로가기와 연결된 파일의 검색 가능성을 높이려면 파일 메타데이터를 삽입하거나 수정할 때 썸네일 이미지와 색인 생성 가능한 텍스트를 모두 업로드하면 됩니다. 자세한 내용은 파일 메타데이터 관리를 참고하세요.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2024-12-21(UTC)"],[[["Third-party shortcuts in Google Drive are metadata-only files that link to files stored outside of Drive on external systems."],["To create a third-party shortcut, use the `files.create` method of the Google Drive API and set the MIME type to `application/vnd.google-apps.drive-sdk`."],["Third-party shortcuts can't be uploaded or downloaded, instead, they redirect users to the external location of the linked file when clicked."],["You can enhance the visibility of third-party shortcuts by adding custom thumbnails and indexable text to their metadata."]]],[]]