在 IOS 上无法从 Google Drive 获取文件

3

这是我的代码。

GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
query.q = [NSString stringWithFormat:@"'%@' IN parents", @"root"];
[self.driveService executeQuery:query completionHandler:^(GTLServiceTicket *ticket,GTLDriveFileList *files, NSError *error)
{
    if (error == nil) {
        if (self.driveFiles == nil) {
            self.driveFiles = [[NSMutableArray alloc] init];
        }
        [self.driveFiles removeAllObjects];
        [self.driveFiles addObjectsFromArray:files.items];
        [tbDownload reloadData];
    } 
    else 
    {
        NSLog(@"An error occurred: %@", error);
    }
}]; 

使用以下代码时出现错误。

发生了一个错误:Error Domain=com.google.GTLJSONRPCErrorDomain Code=401 "The operation couldn’t be completed. (Login Required)" UserInfo=0x8f72a40 {error=Login Required, GTLStructuredError=GTLErrorObject 0x8f647a0: {message:"Login Required" code:401 data:[1]}, NSLocalizedFailureReason=(Login Required)}

我已经在我的应用程序中登录了Google Drive。


我的猜测是您在GTLQueryDrive(共享?)实例中没有正确设置OAuth令牌,或者根本没有设置。 - brandonscript
请问您如何设置OAuth Token,这样我就可以在我的代码中检查它是否正确。 - sunil
没有头绪 - 你完全没有展示那段代码。查看你正在使用的库的文档? - brandonscript
1个回答

0
你可能没有使用成功认证后获取的 GTMOAuth2Authentication 实例来配置你的 GTLServiceDrive
示例代码:
- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController finishedWithAuth:(GTMOAuth2Authentication *)authResult error:(NSError *)error
{
    if (error) {
        // Auth failed, handle the error
    }
    else {
        self.driveService.authorizer = authResult;
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接