banner



How To Access Hidden App Data On Google Drive

The application data folder is a special hidden folder that your app can use to store application-specific data, such as configuration files. The application data folder is automatically created when you attempt to create a file in it. Use this folder to store any files that the user shouldn't directly interact with. This folder is only accessible by your application and its contents are hidden from the user and from other Drive apps.

The application data folder is deleted when a user uninstalls your app from their MyDrive. Users can also delete your app's data folder manually.

Application data folder scope

Before you can access the application data folder, you must request access to the https://www.googleapis.com/auth/drive.appdata scope. For more information about scopes and how to request access to them, refer to Authenticate your users.

Viewing amount of storage used by application data folder

To view the amount of storage used by the application data folder, use the Manage Apps dialog:

Manage apps dialog showing application data folder size

Create a file in the application data folder

To create a file in the application data folder, specify appDataFolder in the parents property of the file and use the files.create method to upload the file to the folder. The following example shows how to insert a file into a folder using a client library:

Java

              File fileMetadata = new File(); fileMetadata.setName("config.json"); fileMetadata.setParents(Collections.singletonList("appDataFolder")); java.io.File filePath = new java.io.File("files/config.json"); FileContent mediaContent = new FileContent("application/json", filePath); File file = driveService.files().create(fileMetadata, mediaContent)     .setFields("id")     .execute(); System.out.println("File ID: " + file.getId());                          

Python

              file_metadata = {     'name': 'config.json',     'parents': ['appDataFolder'] } media = MediaFileUpload('files/config.json',                         mimetype='application/json',                         resumable=True) file = drive_service.files().create(body=file_metadata,                                     media_body=media,                                     fields='id').execute() print 'File ID: %s' % file.get('id')                          

PHP

              $fileMetadata = new Google_Service_Drive_DriveFile(array(     'name' => 'config.json',     'parents' => array('appDataFolder') )); $content = file_get_contents('files/config.json'); $file = $driveService->files->create($fileMetadata, array(     'data' => $content,     'mimeType' => 'application/json',     'uploadType' => 'multipart',     'fields' => 'id')); printf("File ID: %s\n", $file->id);                          

.NET

              var fileMetadata = new File() {     Name = "config.json",     Parents = new List<string>()     {         "appDataFolder"     } }; FilesResource.CreateMediaUpload request; using (var stream = new System.IO.FileStream("files/config.json",     System.IO.FileMode.Open)) {     request = driveService.Files.Create(         fileMetadata, stream, "application/json");     request.Fields = "id";     request.Upload(); } var file = request.ResponseBody; Console.WriteLine("File ID: " + file.Id);                          

Ruby

              file_metadata = {     name: 'config.json',     parents: ['appDataFolder'] } file = drive_service.create_file(file_metadata,                                  fields: 'id',                                  upload_source: 'files/config.json',                                  content_type: 'application/json') puts "File Id: #{file.id}"                          

Node.js

              var fileMetadata = {   'name': 'config.json',   'parents': ['appDataFolder'] }; var media = {   mimeType: 'application/json',   body: fs.createReadStream('files/config.json') }; drive.files.create({   resource: fileMetadata,   media: media,   fields: 'id' }, function (err, file) {   if (err) {     // Handle error     console.error(err);   } else {     console.log('Folder Id:', file.id);   } });                          

Objective-C

              NSData *fileData = [[NSFileManager defaultManager] contentsAtPath:@"files/config.json"];  GTLRDrive_File *metadata = [GTLRDrive_File object]; metadata.name = @"config.json"; metadata.parents = @[@"appDataFolder"];  GTLRUploadParameters *uploadParameters = [GTLRUploadParameters uploadParametersWithData:fileData                                                                                MIMEType:@"application/json"]; uploadParameters.shouldUploadWithSingleRequest = TRUE; GTLRDriveQuery_FilesCreate *query = [GTLRDriveQuery_FilesCreate queryWithObject:metadata                                                                uploadParameters:uploadParameters]; query.fields = @"id"; [driveService executeQuery:query completionHandler:^(GTLRServiceTicket *ticket,                                                      GTLRDrive_File *file,                                                      NSError *error) {     if (error == nil) {         NSLog(@"File ID %@", file.identifier);     } else {         NSLog(@"An error occurred: %@", error);     } }];                          

For further information on creating files in folders, refer to Create and populate folders.

Search for files in the application data folder

To search for files in ithe application data folder, set the spaces field to appDataFolder and use the files.list method. The following example shows how to search for files in the application data folder using a client library:

Java

              FileList files = driveService.files().list()     .setSpaces("appDataFolder")     .setFields("nextPageToken, files(id, name)")     .setPageSize(10)     .execute(); for (File file : files.getFiles()) {   System.out.printf("Found file: %s (%s)\n",       file.getName(), file.getId()); }                          

Python

              response = drive_service.files().list(spaces='appDataFolder',                                       fields='nextPageToken, files(id, name)',                                       pageSize=10).execute() for file in response.get('files', []):     # Process change     print 'Found file: %s (%s)' % (file.get('name'), file.get('id'))                          

PHP

              $response = $driveService->files->listFiles(array(     'spaces' => 'appDataFolder',     'fields' => 'nextPageToken, files(id, name)',     'pageSize' => 10 )); foreach ($response->files as $file) {     printf("Found file: %s (%s)", $file->name, $file->id); }                          

.NET

              var request = driveService.Files.List(); request.Spaces = "appDataFolder"; request.Fields = "nextPageToken, files(id, name)"; request.PageSize = 10; var result = request.Execute(); foreach (var file in result.Files) {     Console.WriteLine(String.Format(         "Found file: {0} ({1})", file.Name, file.Id)); }                          

Ruby

              response = drive_service.list_files(spaces: 'appDataFolder',                                     fields: 'nextPageToken, files(id, name)',                                     page_size: 10) for file in response.files   # Process change   puts "Found file: #{file.name} #{file.id}" end                          

Node.js

              drive.files.list({   spaces: 'appDataFolder',   fields: 'nextPageToken, files(id, name)',   pageSize: 100 }, function (err, res) {   if (err) {     // Handle error     console.error(err);   } else {     res.files.forEach(function (file) {       console.log('Found file:', file.name, file.id);     });   } });                          

Objective-C

                              GTLRDriveQuery_FilesList *query = [GTLRDriveQuery_FilesList query]; query.spaces = @"appDataFolder"; query.fields = @"nextPageToken, files(id, name)"; [driveService executeQuery:query completionHandler:^(GTLRServiceTicket *ticket,                                                      GTLRDrive_FileList *files,                                                      NSError *error) {     if (error == nil) {         for(GTLRDrive_File *file in files) {             NSLog(@"Found file: %@ (%@)", file.name, file.identifier);         }     } else {         NSLog(@"An error occurred: %@", error);     } }];                          

How To Access Hidden App Data On Google Drive

Source: https://developers.google.com/drive/api/v3/appdata

Posted by: randolphimesers.blogspot.com

0 Response to "How To Access Hidden App Data On Google Drive"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel