使用iOS sdk将文件上载到Google drive

使用iOS sdk将文件上载到Google drive,ios,objective-c,iphone,google-drive-api,Ios,Objective C,Iphone,Google Drive Api,在我当前的应用程序中,我正在尝试使用googlesdkforios将.text文件上载到googledrive。但问题是每次我在日志中收到错误消息时,都会显示权限不足,因此如果有人遇到过这种情况或对这种错误有想法,请帮助我 这是我的代码, GTLDriveFile *file = [GTLDriveFile object]; file.descriptionProperty = @"Uploaded from the iOS app."; file

在我当前的应用程序中,我正在尝试使用
googlesdkforios
.text
文件上载到googledrive。但问题是每次我在
日志中收到错误消息时,都会显示
权限不足
,因此如果有人遇到过这种情况或对这种错误有想法,请帮助我

这是我的代码,

        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{

            }
        }];
执行此操作时的日志打印,

        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?) {“错误”:{“代码”:403,“消息”:“权限不足”,“数据”:[{“域”:“全局”,“原因”:“权限不足”,“消息”:“权限不足”}]},“id”:“gtl_3”}

过早失败:上载状态:“最终”位置:(空)我解决了此问题

第一步 将范围更改为
[kGTLAuthScopeDriveFile]

但在第一步之后,我得到了相同的403错误

因为我手机中的应用程序具有作用域
[kGTLAuthScopeDriveMetadataReadonly]

第二步 重置我的应用程序或在另一个模拟器中构建

我认为第一个使用scope readonly的身份验证密钥链是存在的,所以不会将文件写入GoogleDrive

更改范围并重新验证后,它就可以工作了

如果将
kKeychainItemName
的值更改为另一个值,则可以使用新范围再次进行身份验证

谷歌在快速入门教程中说

// If modifying these scopes, delete your previously saved credentials by
// resetting the iOS simulator or uninstall the app.
// private let scopes = [kGTLAuthScopeDriveFile]
我解决这个问题

第一步 将范围更改为
[kGTLAuthScopeDriveFile]

但在第一步之后,我得到了相同的403错误

因为我手机中的应用程序具有作用域
[kGTLAuthScopeDriveMetadataReadonly]

第二步 重置我的应用程序或在另一个模拟器中构建

我认为第一个使用scope readonly的身份验证密钥链是存在的,所以不会将文件写入GoogleDrive

更改范围并重新验证后,它就可以工作了

如果将
kKeychainItemName
的值更改为另一个值,则可以使用新范围再次进行身份验证

谷歌在快速入门教程中说

// If modifying these scopes, delete your previously saved credentials by
// resetting the iOS simulator or uninstall the app.
// private let scopes = [kGTLAuthScopeDriveFile]
请通过此链接也尝试此请通过此链接也尝试此