1

我正在尝试在我的 iOS 应用中使用 Google Drive。我尝试上传文件,我收到以下错误:

*** Assertion failure in -[GTMHTTPUploadFetcher connectionDidFinishLoading:], 

/Users/mac/Desktop/google-api-objectivec-client-mirror-master/Source/HTTPFetcher/GTMHTTPUploadFetcher.m:399

以下是断言发生时突出显示的代码:

NSAssert([[self downloadedData] length] == 0,
                @"unexpected response data (uploading to the wrong URL?)");

上传图片到谷歌驱动器:

- (void)uploadPhoto
{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"'Quickstart Uploaded File ('EEEE MMMM d, YYYY h:mm a, zzz')"];
GTLDriveFile *file = [GTLDriveFile object];
file.title = [dateFormat stringFromDate:[NSDate date]];
file.descriptionProperty = @"Uploaded from the Google Drive iOS Quickstart";
file.mimeType = @"image/png";

UIImage   *img =[UIImage imageNamed:@"Default.png"];
NSData *data = UIImagePNGRepresentation(img);

GTLUploadParameters *uploadParameters = [GTLUploadParameters uploadParametersWithData:data MIMEType:file.mimeType];
GTLQueryDrive *query = [GTLQueryDrive queryForFilesInsertWithObject:file
                                                   uploadParameters:uploadParameters];
UIAlertView *waitIndicator = [self showWaitIndicator:@"Uploading to Google Drive"];

[self.driveService executeQuery:query
              completionHandler:^(GTLServiceTicket *ticket,GTLDriveFile *insertedFile, NSError *error)
 {
     [waitIndicator dismissWithClickedButtonIndex:0 animated:YES];
     if (error == nil)
     {
         NSLog(@"File ID: %@", insertedFile.identifier);
         [self showAlert:@"Google Drive" message:@"File saved!"];
     }
     else
     {
         NSLog(@"An error occurred: %@", error);
         [self showAlert:@"Google Drive" message:@"Sorry, an error occurred!"];
     }
 }];
  }
4

1 回答 1

1

试试这个,

我纠正了 GTMHTTPUploadFetcher connectionDidFinishLoading 中的 Assertion failure”)错误,不幸的是我忘记启用Google API Console Drive API

1.创建一个应用程序。

2.转到服务,打开“Drive API”。

在此处输入图像描述

您需要从 API 控制台/服务选项卡启用 Drive API 和 Drive SDK

于 2013-08-23T07:42:02.673 回答