GTMHTTPUploadFetcher connectionDidFinishLoading中的断言失败

时间:2013-08-15 20:58:41

标签: ios objective-c google-drive-api

我在将文件上传到Google云端硬盘时遇到问题。我仔细按照说明操作,我可以登录并验证用户身份,但是当我上传文件时,我会遇到以下断言:

  

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

我仔细检查并确保-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。

1 个答案:

答案 0 :(得分:0)

发现问题。您需要从API控制台/服务标签中启用Drive API和Drive SDK。这是有帮助的帖子:

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