使用iOS sdk将文件上传到Google驱动器 [英] Uploading a file to Google drive using iOS sdk

查看:149
本文介绍了使用iOS sdk将文件上传到Google驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我目前的应用程序中,我正尝试使用 Google SDK for iOS 上传 .text 文件到Google Drive >。但问题在于,我每次收到 Log 中的错误消息都是 权限不足 ,所以如果有人遇到这种情况或者对这种类型的错误有所了解,请帮助我。



这是我的代码,

  GTLDriveFile * file = [GTLDriveFile object]; 
file.descriptionProperty = @从iOS应用上载。;
file.mimeType = @text / *;
file.name = @MyTextFile;
NSString * filePath = [[NSBundle mainBundle] pathForResource:@myTestFileofType:@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: %@,错误);
} else {

}
}];

执行此操作时记录日志,



意外的响应数据(上传到错误的URL?)
{error:{code:403,message:Permission Permission ,data:[{domain:global,reason:insufficientPermissions,message:Insufficient Permission}]},id:gtl_3}



过早失败:upload-status:finallocation:(null)

解决方案

我解决了这个问题

第一步



将您的范围更改为 [kGTLAuthScopeDriveFile]



第一步,我得到了同样的403错误,因为我手机中的APP有范围 [kGTLAuthScopeDriveMetadataReadonly]

p>

第二步



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



我认为第一个认证密钥cha在使用范围只读存在,所以不写文件到谷歌驱动器



后更改范围和重新验证然后它的作品



如果您将 kKeychainItemName 的值更改为另一个,则可以使用新范围重新授权

google在快速入门教程中说过

  //如果修改这些范围,请删除以前保存的凭证
// resetting iOS模拟器或卸载应用程序。
// private let scopes = [kGTLAuthScopeDriveFile]


In my current application, I am trying to upload a .text file to google drive using Google SDK for iOS. But the issue is every time I got the error message in my Log as Insufficient Permission, so If anyone have faced this or have an idea on this type of error kindly help me.

Here is my code,

        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{

            }
        }];

Log print when this action is performed,

unexpected response data (uploading to the wrong URL?) {"error":{"code":403,"message":"Insufficient Permission","data":[{"domain":"global","reason":"insufficientPermissions","message":"Insufficient Permission"}]},"id":"gtl_3"}

Premature failure: upload-status:"final" location:(null)

解决方案

I solve this problem

First Step

change your scope to [kGTLAuthScopeDriveFile]

but after first step, i got a same 403 error

because my APP in my phone have scope [kGTLAuthScopeDriveMetadataReadonly]

Second Step

reset my application or build in another simulator

I think first auth key chain using scope readonly was existed so doesn't write file to google drive

after change scope and re-auth then it works

if you change kKeychainItemName's value to another then could re-auth again with new scope

google says in Quickstart tutorial

// If modifying these scopes, delete your previously saved credentials by
// resetting the iOS simulator or uninstall the app.
// private let scopes = [kGTLAuthScopeDriveFile]

这篇关于使用iOS sdk将文件上传到Google驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆