Upload file To Google Drive with Objective C

324 views
Skip to first unread message

Giordano Vicoli

unread,
Apr 17, 2018, 1:51:38 PM4/17/18
to Google APIs Client Library for Objective-C
Hello everybody,

I am trying to upload a file to Google Drive in Objective c.
I am following the below example but I have the following error: insufficient permission.

What do I have to do? Please, help me.

Thanks and regards,
Giordano


NSData *fileData = [[NSFileManager defaultManager] contentsAtPath:@"files/photo.jpg"];

GTLRDrive_File *metadata = [GTLRDrive_File object];
metadata
.name = @"photo.jpg";

GTLRUploadParameters *uploadParameters = [GTLRUploadParameters uploadParametersWithData:fileData
                                                                               
MIMEType:@"image/jpeg"];
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);
   
}
}];

Thomas Van Lenten

unread,
Apr 17, 2018, 2:06:16 PM4/17/18
to Google APIs Client Library for Objective-C
You snippet doesn't really say how your `driveService` was created, but it likely needs an `authorizer` set on it.


TVL
Reply all
Reply to author
Forward
0 new messages