iphone - 如何在谷歌驱动器上上传图片(错误 "Assertion failure in GTMHTTPUploadFetcher connectionDidFinishLoading")

标签 iphone ios google-drive-api

我正在尝试在我的 iOS 应用程序中使用 Google 云端硬盘。我尝试上传文件,但出现以下错误:

*** 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!"];
     }
 }];
  }

最佳答案

试试这个,

我纠正了 GTMHTTPUploadFetcher connectionDidFinishLoading 中的断言失败”)错误,不幸的是我忘记启用 Google API Console驱动 API

1.创建应用。

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

enter image description here

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

关于iphone - 如何在谷歌驱动器上上传图片(错误 "Assertion failure in GTMHTTPUploadFetcher connectionDidFinishLoading"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18288487/

相关文章:

iphone - 从 UINavigationController 子屏幕返回时如何维护 UITableView 选定行?

javascript - 从node.js googledrive api返回结果

javascript - 谷歌云端硬盘 SDK - JavaScript : How to list SHARED FILES (not shared with me)

ios - 如何将 float 保存到只有两位小数的 nsnumber

ios - 执行 webView.loadRequest(request) 时出现 "unexpectedly found nil ..."错误

ios - 提取 JSON 并将其保存在 NSMutableArray 中

javascript - google drive sdk - 如何通过 JavaScript 上传一个简单的文件

iphone - 核心数据 : Ubiquity: Using local storage: 1 never becomes 0

iphone - 如何根据存储在其中的NSString重新排序NSMutable数组?

iphone - iOS/iPhone 用户关于重复 NSNotification 观察的警告