ios - 错误域 = MCOErrorDomain 代码 = 5 "Unable to authenticate with the current session' s 凭据。”

标签 ios objective-c google-signin mailcore2 gidsignin

我在调用 imapSession 的 checkAccountOperation 方法时收到此错误

Error Domain=MCOErrorDomain Code=5 "Unable to authenticate with the current session's credentials." UserInfo={NSLocalizedDescription=Unable to authenticate with the current session's credentials.}

这是我的代码:

MCOIMAPSession *session = [[MCOIMAPSession alloc] init];
session.dispatchQueue = self.imapQueue;
session.hostname = @"imap.gmail.com";
session.port = 993;
session.maximumConnections = 2;
session.username = emailAddress; //email address with which I logged in
session.password = nil;
session.OAuth2Token = accessToken; // access Token got in success response of google sign in
session.authType = MCOAuthTypeXOAuth2;
session.connectionType = MCOConnectionTypeTLS;
dispatch_async(self.imapQueue, ^{
    MCOIMAPOperation *imapCheckOp = [session checkAccountOperation];

    [imapCheckOp start:^(NSError *errorResults)
     {
         NSLog(@"%@",errorResults);
     }];
});

我正在使用Google Sign in SDK来登录Google帐户

self.googleSignIn = [GIDSignIn sharedInstance];
self.googleSignIn.delegate = self;
self.googleSignIn.uiDelegate = self;
NSString *path = [[NSBundle mainBundle] pathForResource: @"GoogleService-Info" ofType: @"plist"];
NSMutableDictionary *googleDictplist =[[NSMutableDictionary alloc] initWithContentsOfFile:path];
NSString *googleClientId = [NSString stringWithFormat:@"%@",[googleDictplist objectForKey:@"CLIENT_ID"]];
self.googleSignIn.clientID = googleClientId;
[self.googleSignIn signIn];

对于同一问题,我已经尝试了从网上获得的几乎所有可能的解决方案。我已在 Google Developer 控制台下为我的项目启用了所有所需的 API。即使我在创建 imapSession 时提供了密码,这个问题仍然存在。在我将登录更新为使用最新的 Google Sign in SDK 的方式后,开始遇到此问题。

最佳答案

您尚未为 google 登录实例指定任何范围。尝试添加相同的范围

self.googleSignIn.scopes = [NSArray arrayWithObjects:@"https://www.googleapis.com/auth/userinfo.profile" ,@"https://www.googleapis.com/auth/userinfo.email", @"https://mail.google.com",@"https://www.google.com/m8/feeds/", nil];

关于ios - 错误域 = MCOErrorDomain 代码 = 5 "Unable to authenticate with the current session' s 凭据。”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43603536/

相关文章:

Swift:在 View 加载时使用 Google 提示登录

ios - 如何延迟或减慢 View Controller 之间的转换?

ios - 动画时移动 Action

android - 如何使用 Google Provider 重新验证 Firebase 上的用户?

java - Spring Social Google - 将一次性授权代码转换为服务器上的访问 token /刷新 token

ios - 当用户点击文本字段外的其他区域时如何关闭键盘?

ios - 我可以在同一 View Controller 中添加两个选项卡栏,一个选项卡栏在底部,一个选项卡栏在顶部

ios - 如何使用 iOS API 将 KML 文件 URL 加载到 Google map 中?

ios - Swift 应用程序在打开后退出,在 Xcode 中运行

objective-c - obj-c中的这些错误意味着什么?