【问题标题】:Downloading file from Google Drive using iOS SDK使用 iOS SDK 从 Google Drive 下载文件
【发布时间】:2016-05-26 15:45:28
【问题描述】:

我正在尝试使用为 iOS 提供的 SDK 从 Google Drive 下载文件。但它给了我这个错误:

错误域=com.google.HTTPStatus Code=400 "(null)"

这里是下载代码:

GTLDriveFile *file = [driveFiles objectAtIndex:indexPath.row];
NSString *url = [NSString stringWithFormat:@"https://www.googleapis.com/drive/v3/files/%@?alt=media",
                 file.identifier];
GTMSessionFetcher *fetcher = [self.service.fetcherService fetcherWithURLString:url];

[fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error) {
    if (error == nil) {
        NSLog(@"Retrieved file content");
        // Do something with data
    } else {
        NSLog(@"An error occurred: %@", error);
    }
}];

但是我能够列出所有文件,并且我还仔细检查了包标识符。

有什么我缺少的建议吗?

【问题讨论】:

    标签: ios objective-c google-drive-api google-developer-tools


    【解决方案1】:

    在 URL 中添加密钥(iOS 的 API 密钥)参数 然后尝试如下代码:

    GTLDriveFile *file;//Your Object
    NSString *url = [NSString stringWithFormat:@"https://www.googleapis.com/drive/v3/files/%@?key=YOUR_KEY_iOS",
                     file.identifier];
    GTMSessionFetcher *fetcher = [self.service.fetcherService fetcherWithURLString:url]; //GTLServiceDrive *service;
    
    [fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error) {
        if (error == nil) {
            NSLog(@"Retrieved file content");
            // File Download here
        } else {
            NSLog(@"An error occurred: %@", error);
        }
    }];
    

    【讨论】:

    • 它给了我这个错误:发生错误:Error Domain=com.google.HTTPStatus Code=401 "(null)" 与上面的有点不同。
    • 这意味着....无效的授权标头。您使用的访问令牌已过期或无效.......请看这个..developers.google.com/drive/v3/web/…
    【解决方案2】:

    我已经尝试成功,但没有使用以下代码。NSString *url = [NSString stringWithFormat:@"https://www.googleapis.com/drive/v3/files/%@?alt=media", file.identifier]; 我用file.webContentLink

    【讨论】:

    • file.webContentLink 给了我零。
    猜你喜欢
    • 1970-01-01
    • 2013-03-29
    • 2013-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多