我正在尝试在我的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?)");
将图片上传到Google云端硬盘:
- (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!"];
}
}];
}
答案 0 :(得分:1)
试试这个,
我在GTMHTTPUploadFetcher connectionDidFinishLoading“)中纠正了断言失败,但遗憾的是我忘了启用Google API Console Drive API
1.创建一个应用程序。
2.转到“服务”,打开“Drive API”。
您需要从API控制台/服务标签
启用Drive API和Drive SDK