ios - GTMHTTPUploadFetcher connectionDidFinishLoading中的断言失败

标签 ios objective-c google-drive-api

我无法将文件上传到Google云端硬盘。我仔细地按照说明进行操作,我能够登录并验证用户身份,但是当我上传文件时,我受到以下声明的打击:

*-[GTMHTTPUploadFetcher connectionDidFinishLoading:],/ Users /.../ google-api-objectivec-client-read / only / Source / HTTPFetcher / GTMHTTPUploadFetcher.m:399中的断言失败

我仔细检查并确保-ObjC -all_load在其他链接器标志中。

这是我使用的代码,基本上只是Google在其示例中使用的代码的一个副本。

NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *localPath = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/%@",
                      localPath,fileNameString];

NSData *myFileData = [NSData dataWithContentsOfFile:filePath];

GTLDriveFile *file = [GTLDriveFile object];
file.title = fileNameString;
file.descriptionProperty = fileNameString;
file.mimeType = @"application/pdf";

GTLUploadParameters *uploadParameters = [GTLUploadParameters
                                         uploadParametersWithData:myFileData
                                         MIMEType:@"application/pdf"];

GTLQueryDrive *query = [GTLQueryDrive queryForFilesInsertWithObject:file
                                                   uploadParameters:uploadParameters];

[self.driveService executeQuery:query
              completionHandler:^(GTLServiceTicket *ticket,
                                  GTLDriveFile *updatedFile,
                                  NSError *error) {
                  if (error == nil) {
                      NSLog(@"file uploaded");
                  } else {
                      NSLog(@"upload failed");            
                  }
              }];

这是断言发生时突出显示的代码:
  // The initial response of the resumable upload protocol should have an
  // empty body
  //
  // This assert typically happens because the upload create/edit link URL was
  // not supplied with the request, and the server is thus expecting a non-
  // resumable request/response.
  NSAssert([[self downloadedData] length] == 0,
                    @"unexpected response data (uploading to the wrong URL?)");

有人知道他们指的是什么网址吗?我还没有看到URL用于在任何地方上传新文件。

最佳答案

找到了问题。您需要通过“API控制台/服务”标签启用Drive API和Drive SDK。以下是提供帮助的帖子:

Google Drive HTTP 403 "Access Not Configured" error with DrEdit

关于ios - GTMHTTPUploadFetcher connectionDidFinishLoading中的断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18261724/

相关文章:

ios - 如何使用官方 App Store Connect API 创建和请求类型为 "Apple Development"或 "Apple Distribution"的证书?

objective-c - 越狱的iOS设备是否可以在后台捕获触摸事件?

ios - 2 items segment control with UITableView iOS

oauth - Google 云端硬盘 7 天刷新 token

iphone - 音频队列启动失败

ios - 我有 4 个不同的 xcode 项目。我想从一个项目调用不同项目的 viewcontroller。我该怎么做

objective-c - 为什么不设置值:forKeyPath invoked on mutable dictionary throw exception for unknown keypaths?

c# - 使用带有 OAuth 的 C# Google Drive API 上传文件时,如何更改显示在 Google Drive 文件详细信息中的创建名称?

c# - 我可以使用 C# 在浏览器中查看谷歌驱动器中的文件吗

android - 适用于 iOS 加速框架