使用iOS sdk将文件上传到Google云端硬盘
在我目前的应用程序中,我正在尝试使用Google SDK for iOS
将.text
文件上传到Google驱动器。 但问题是每次我在我的Log
收到错误消息作为Insufficient Permission
,所以如果有人遇到这个或对这种类型的错误有所了解,请帮助我。
这是我的代码,
GTLDriveFile *file = [GTLDriveFile object]; file.descriptionProperty = @"Uploaded from the iOS app."; file.mimeType = @"text/*"; file.name=@"MyTextFile"; NSString *filePath = [[NSBundle mainBundle] pathForResource:@"myTestFile" ofType:@"txt"]; GTLUploadParameters *uploadParameters = [GTLUploadParameters uploadParametersWithFileURL:[NSURL URLWithString:filePath] MIMEType:file.mimeType]; GTLQueryDrive *query = [GTLQueryDrive queryForFilesCreateWithObject:file uploadParameters:uploadParameters]; [self.service executeQuery:query completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error) { if (error) { NSLog(@"Error: %@", error); }else{ } }];
执行此操作时记录打印,
意外的响应数据(上传到错误的URL?){“error”:{“code”:403,“message”:“权限不足”,“数据”:[{“domain”:“global”,“reason”: “insufficientPermissions”,“message”:“权限不足”}}},“id”:“gtl_3”}
过早失败:upload-status:“final”位置:(null)
我解决了这个问题
第一步
将您的范围更改为[kGTLAuthScopeDriveFile]
但在第一步之后,我得到了同样的403错误
因为我的手机中的APP有范围[kGTLAuthScopeDriveMetadataReadonly]
第二步
重置我的应用程序或在另一个模拟器中构建
我认为首先使用范围readonly的auth密钥链是存在的,所以不写文件到谷歌驱动器
在更改范围和重新validation后,它工作
如果您将kKeychainItemName
的值更改为另一个,则可以使用新范围再次重新validation
谷歌在快速入门教程中说
// If modifying these scopes, delete your previously saved credentials by // resetting the iOS simulator or uninstall the app. // private let scopes = [kGTLAuthScopeDriveFile]