无法从iOS中的Google Drive获取文件 [英] Failed to get the files from Google Drive in IOS
问题描述
这是我的代码。
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);
}
}];
我使用这段代码得到错误。
n发生错误:错误域= com.google.GTLJSONRPCErrorDomain代码= 401无法完成操作(需要登录) UserInfo = 0x8f72a40 {error = Login Required,GTLStructuredError = GTLErrorObject 0x8f647a0:{message:Login Requiredcode:401 data:[1]},NSLocalizedFailureReason =(需要登录)}
我已经在我的应用程序中使用谷歌驱动器登录。 您可能没有配置 示例代码: GTLServiceDrive
,其中
(GTMOAuth2Authentication *)authResult错误:(NSError *)错误
{
if(error){pre $
// Auth失败,处理错误
}
else {
self.driveService.authorizer = authResult;
}
}
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 .
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;
}
}
这篇关于无法从iOS中的Google Drive获取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!