我是IOS开发的新手。我使用oauth 2.0进行身份验证和访问令牌。现在我想使用mailcore2中的令牌来获取电子邮件。我怎么能这样做。我有很多东西,但它不值得。所以,请帮助解决这个问题.. 提前致谢。这是我的代码。
- (void)viewDidLoad {
[super viewDidLoad];
NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
NSString *accessToken = [def objectForKey:@"sessionToken"];
NSLog(@"Access token:%@",accessToken);//token from google api authentication
session = [[MCOIMAPSession alloc] init];
session.hostname = @"imap.gmail.com";
session.port = 993;
session.authType =MCOAuthTypeXOAuth2;
session.OAuth2Token = accessToken;
session.username = emailId;
session.connectionType = MCOConnectionTypeTLS;
session.password = nil;
[session setConnectionLogger:^(void * connectionID, MCOConnectionLogType type,
NSData * data){
NSLog(@"MCOIMAPSession: [%i] %@", type, [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
}];
MCOIMAPMessagesRequestKind requestKind = (MCOIMAPMessagesRequestKind (MCOIMAPMessagesRequestKindHeaders | MCOIMAPMessagesRequestKindStructure |MCOIMAPMessagesRequestKindInternalDate | MCOIMAPMessagesRequestKindHeaderSubject |MCOIMAPMessagesRequestKindFlags);
MCOIMAPFolderInfoOperation *inboxFolderInfo = [session folderInfoOperation:Folder];
[inboxFolderInfo start:^(NSError *error, MCOIMAPFolderInfo *info){
NSLog(@"INFO:%@",info);
}];
}
我得到了INFO :( null)。纠正我如果我做错了什么。