Failed to get the files from Google Drive in IOS

2019-05-11 08:51发布

Here is my code .

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);
    }
}]; 

I'm getting the error by using this code .

n error occurred: 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)}

I Already login with google drive in my app .

1条回答
不美不萌又怎样
2楼-- · 2019-05-11 09:17

You probably aren't configuring your GTLServiceDrive with the GTMOAuth2Authentication instance you get after successful authentication.

Example code:

- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController finishedWithAuth:(GTMOAuth2Authentication *)authResult error:(NSError *)error
{
    if (error) {
        // Auth failed, handle the error
    }
    else {
        self.driveService.authorizer = authResult;
    }
}
查看更多
登录 后发表回答