【问题标题】:Insert file into appdata folder将文件插入 appdata 文件夹
【发布时间】:2013-06-21 05:44:04
【问题描述】:

我正在开发 Mac 应用程序并希望将文件存储在 Google 驱动器中。这些文件应该对用户隐藏。所以我的选择是保存在“appdata”文件夹中。使用Drive sample code 上传文件。要将文件插入“appdata”文件夹,请使用此sample code。但是当我插入文件时,用户可以看到它。它不是隐藏的。

  1. 所以请让我知道Drive sample code 需要进行哪些更改才能将文件上传到“appdata”私人文件夹。 ?
  2. 我需要吗 第一次创建“appdata”文件夹?

【问题讨论】:

标签: objective-c google-drive-api


【解决方案1】:

Drive Sample进行以下更改后,成功将文件上传到应用数据文件夹:

  1. 修改 API 范围以选择“https://www.googleapis.com/auth/drive.appdata”:

GTMOAuth2WindowController *windowController = [GTMOAuth2WindowController controllerWithScope:@"https://www.googleapis.com/auth/drive.appdata" clientID:clientID clientSecret:clientSecret keychainItemName:kKeychainItemName resourceBundle:frameworkBundle];

2.获取父文件引用。这里的“appdata”文件夹是父文件夹:

GTLQuery *query = [GTLQueryDrive queryForFilesGetWithFileId:@"appdata"];
        [service executeQuery:query
            completionHandler:^(GTLServiceTicket *ticket, GTLDriveFile *parentfile,
                                NSError *error) {
                /*Save parentfile for future reference*/}];

3.上传设置文件父级到应用数据文件夹时。使用上一步获得的父文件引用

GTLDriveParentReference *parentRef = [GTLDriveParentReference object];
        parentRef.identifier = parentfile.identifier;
        fileToUpload.labels.hidden = @YES;
        fileToUpload.parents = [NSArray arrayWithObjects: parentRef, nil];

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-14
  • 2015-12-21
  • 1970-01-01
  • 2015-03-26
  • 1970-01-01
相关资源
最近更新 更多