How can I use MailCore to fetch emails using the token I got from gmail?

704 Views Asked by At

I am new to IOS developement.I have use oauth 2.0 for authentication and access token.now i want to fetch the emails using token in mailcore2. how can I do it.I had google lots of stuff but it does not worth it . So,Please help to solve this problem.. Thanks in advance. Here is my code.

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

I got INFO:(null).correct me If i am doing wrong stuff.

0

There are 0 best solutions below