2

Using the Google Drive iOS API, how can I create a folder AND share it?

GTLDriveFile * folder = [GTLDriveFile object];
folder.title = @"Test";
folder.mimeType = @"application/vnd.google-apps.folder";
// ???
Kara
  • 6,115
  • 16
  • 50
  • 57
user3246173
  • 488
  • 6
  • 18

1 Answers1

0

May be this one helps you. This code is for creating folder with specific name.

Code 1 :

    -(void)createFolderWithName:(NSString *)folderName {

        GTLDriveFile *file = [GTLDriveFile object];
        file.title = @"FileUpload";
        file.mimeType = @"application/vnd.google-apps.folder";
// To create a folder in a specific parent folder, specify the identifier
    // of the parent:
    // _resourceId is the identifier from the parent folder. Here i am using root as the parent folder.
        NSString *resourceId = @"root";
        if (resourceId.length && ![resourceId isEqualToString:@"0"]) {
            GTLDriveParentReference *parentRef = [GTLDriveParentReference object];
            parentRef.identifier = resourceId;
            file.parents = [NSArray arrayWithObject:parentRef];
        }

        GTLQueryDrive *query1 = [GTLQueryDrive queryForFilesInsertWithObject:file uploadParameters:nil];

        [[self appDelegate].driveService executeQuery:query1 completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error) {

            if (!error) {
                //I see this in the console...
                //No Errors in Folder Query:
                //GTLDriveFileList 0x108f3430: {kind:"drive#fileList"
                //etag:""Q5ElJByAJoL0etObruYVPRipH1k/vyGp6PvFo4RvsFtPoIWeCReyIC8""}
                NSLog(@"No Errors in Folder Query: %@",object);

                GTLDriveFileList *list = (GTLDriveFileList *)object;

                //So, none of this for() loop happens
                for (GTLDriveFile *file in list.items) {
                    NSLog(@"Folder: \n \n %@ \n \n",file);
                    //NSLog(@"\n file extension value is %@",file.fileExtension);
                    //NSLog(@"\n file size value is %@",file.fileSize);
                }
            } else {
                NSLog(@"Folder Query Error: %@",error);
            }
        }];
    }

In the above code resourceId is the parent folder id, under which u want to create the folder.

I don't know how to share the full folder, but i think it is same like sharing the file.

If u want to know about particular file sharing please refer this link. In the link you can find the example for objective-c code. https://developers.google.com/drive/v2/reference/permissions/insert

Koti Tummala
  • 746
  • 6
  • 8