我在调用 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/