Reputation: 11
Using the Quickstart app for iOS I was able to get Google Drive browsing files and folders, displaying icons and thumbnails, and downloading files. However, when it comes to uploading I get the following error:
An error occurred: Error Domain=com.google.GTLRErrorObjectDomain Code=403 "Insufficient Permission" UserInfo={GTLRStructuredError=GTLRErrorObject 0x61800024ff90: {message:"Insufficient Permission" errors:[1] code:403}, NSLocalizedDescription=Insufficient Permission}
From the comments here and on the Google forum it seems I need to use the Drive scope but I can't figure out how to do that. Here's the callback from the sign-in:
- (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)error {
if (error != nil) {
[self showAlert:@"Authentication Error" message:error.localizedDescription];
_driveService.authorizer = nil;
} else {
self.signInButton.hidden = true;
_driveService.authorizer = user.authentication.fetcherAuthorizer;
[self signedIn];
[self listFilesFromFolderID:[self initialFolder]];
}
}
Then, to upload the file I'm doing this:
_driveFile = [GTLRDrive_File object];
_driveFile.name = [NSString stringWithFormat:@"%@.%@", _filenameToSave, _fileExtension];
_driveFile.mimeType = _fileMimeType;
NSString *parentRef = @"root";
if ( self.currentFolder )
parentRef = [self.currentFolder.identifier copy];
_driveFile.parents = @[ parentRef ];
GTLRUploadParameters *uploadParameters = [GTLRUploadParameters uploadParametersWithData:fileData
MIMEType:_driveFile.mimeType];
uploadParameters.shouldUploadWithSingleRequest = TRUE;
GTLRDriveQuery_FilesCreate *query = [GTLRDriveQuery_FilesCreate queryWithObject:_driveFile
uploadParameters:uploadParameters];
query.fields = @"id";
[self.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);
}
}];
Upvotes: 1
Views: 840
Reputation: 5186
The issue is in given permission while doing SignIn into Google. Kindly check scopes which you gave during sign-in.
GIDSignIn* signIn = [GIDSignIn sharedInstance];
signIn.delegate = self;
signIn.uiDelegate = self;
signIn.scopes = [NSArray arrayWithObjects:kGTLRAuthScopeDrive, nil];
Changes:
kGTLRAuthScopeDriveReadonly --> kGTLRAuthScopeDrive
I put it kGTLRAuthScopeDriveReadonly and getting the same error. Just check with code about same.
Upvotes: 8