【问题标题】:Google Drive API downloadUrl 404 in iOSiOS中的Google Drive API下载Url 404
【发布时间】:2013-08-16 10:46:28
【问题描述】:

所以我试图让两个用户交换各自在其 Google 云端硬盘中的文件。这涉及知道其他人文件的 ID 并使用 API 调用来检索它。这两个文件都位于已共享给任何人/公众的文件夹中。

问题是当我执行下面的代码时,我发现每个用户只能使用与他们拥有的文件相对应的 downloadUrl - 其他人返回 404。在这种情况下,“我的”或“他们的”取决于帐户我已登录。

    // _driveService and its authorizer setup elsewhere        

    // Retrieve the metadata then the actual data
    NSString *mine = @"0B4Pba9IBDsR3T1NVTC1XSGJTenc";
    NSString *theirs = @"0B4n9OyY8tqWpNlNaN1dUc3FsNG8";
    NSString *get = [NSString stringWithFormat:@"https://www.googleapis.com/drive/v2/files/%@",theirs];
    [_driveService fetchObjectWithURL:[NSURL URLWithString:get] completionHandler:^
     (GTLServiceTicket *ticket, GTLDriveFile *file, NSError *error)
     {
         if (error != nil)
             NSLog(@"Error retrieving metadata: %@", error);
         else
         {
             // Download the actual data
             GTMHTTPFetcher *fetcher = [_driveService.fetcherService fetcherWithURLString:file.downloadUrl];
             [fetcher beginFetchWithCompletionHandler:^
              (NSData *data, NSError *error)
              {
                  if (error != nil)
                      NSLog(@"Error retrieving actual data: %@", error);
                  else
                  {
                      NSString *content = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
                      NSLog(@"Content: %@", content);
                  }
              }];
         }
     }];

检索实际数据时出错:Error Domain=com.google.HTTPStatus Code=404 “无法完成操作。(com.google.HTTPStatus 错误 404。)”

我在这里做错了什么?如果是权限问题,为什么允许我获取元数据?

请注意,这是针对 iOS 应用的,这两个文件都是使用官方客户端 API(rev 353)从应用创建和上传的。

【问题讨论】:

  • 我正在尝试下载 Google 驱动器文件的 URL。我尝试使用 AuthDriveScopeFile 但没有收到 404 错误。
  • 如果应用程序使用请求下载 URL 的同一用户帐户将文件放在那里,则 AuthDriveScopeFile 将正常工作

标签: ios google-drive-api


【解决方案1】:

哈,看来魔鬼在我没有提及的细节中。在创建授权方时,我提供的范围是 kGTLAuthScopeDriveFile,这是示例中的默认值,当到目前为止一切正常时我都忘记了它。显然我需要使用 kGTLAuthScopeDrive 代替(差异解释here

这里的逻辑似乎有点缺陷,我的意思是我不想访问不是使用该应用程序创建的其他文件,我只想访问其他人使用该应用程序创建的公共文件...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多