gpt4 book ai didi

ios - 如何在 Google 云端硬盘上保存和检索图像

转载 作者:行者123 更新时间:2023-11-29 01:39:37 24 4
gpt4 key购买 nike

我已成功将谷歌驱动器完全集成到我的应用程序中,但我将坚持在谷歌驱动器上保存和获取图像我写了下面的代码

 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 *imagenda=[UIImage imageNamed:@"back_button.png"];
// NSData *data = UIImagePNGRepresentation(imagenda, 1.0);
// add image data
NSData *data = UIImageJPEGRepresentation(imagenda, 1.0);
GTLUploadParameters *uploadParameters = [GTLUploadParameters uploadParametersWithData:data MIMEType:file.mimeType];
GTLQueryDrive *query = [GTLQueryDrive queryForFilesInsertWithObject:file
uploadParameters:uploadParameters];
// UIAlertView *waitIndicator = [self showWaitIndicator:@"Uploading to Google Drive"];

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

最佳答案

您需要添加作用域:-

// Authorization scope
NSString * const kGTLAuthScopeDrive = @"https://www.googleapis.com/auth/drive";
NSString * const kGTLAuthScopeDriveAppdata = @"https://www.googleapis.com/auth/drive.appdata";
NSString * const kGTLAuthScopeDriveAppsReadonly = @"https://www.googleapis.com/auth/drive.apps.readonly";
NSString * const kGTLAuthScopeDriveFile = @"https://www.googleapis.com/auth/drive.file";
NSString * const kGTLAuthScopeDriveMetadataReadonly = @"https://www.googleapis.com/auth/drive.metadata.readonly";
NSString * const kGTLAuthScopeDriveReadonly = @"https://www.googleapis.com/auth/drive.readonly";
NSString * const kGTLAuthScopeDriveScripts = @"https://www.googleapis.com/auth/drive.scripts";



// Creates the auth controller for authorizing access to Drive API.
- (GTMOAuth2ViewControllerTouch *)createAuthController {
GTMOAuth2ViewControllerTouch *authController;
NSArray *scopes = [NSArray arrayWithObjects:kGTLAuthScopeDriveFile, nil];
authController = [[GTMOAuth2ViewControllerTouch alloc]
initWithScope:[scopes componentsJoinedByString:@" "]
clientID:kClientID
clientSecret:kClientSecret
keychainItemName:kKeychainItemName
delegate:self
finishedSelector:@selector(viewController:finishedWithAuth:error:)];
return authController;
}

关于ios - 如何在 Google 云端硬盘上保存和检索图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32561972/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com