无法在没有密码的情况下登录Gmail

时间:2016-03-10 14:58:39

标签: ios objective-c gmail-api mailcore2 mailcore

我已经尝试了所有内容并按照每个链接但仍然没有成功。我想在不使用密码的情况下登录,因此我将密码分配给nil。如果我提供正确的密码用户登录成功,但我已登录没有密码和使用令牌..我有客户端ID和名称跟随console.google教程,但没有秘密ID,因为它不适用于ios ..这是我的代码每件事都可以正常使用密码,但不能使用令牌。

  NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(self.emailimage)];
NSString *base64String = [imageData base64EncodedString];
 AppDelegate *tokenD = [[UIApplication sharedApplication]delegate];
NSString * email =tokenD.username;
NSString * accessToken =tokenD.Dtoken;
NSDate *now = [NSDate date];

double seconds1 = [now timeIntervalSince1970];
NSNumber *seconds = [NSNumber numberWithInteger:seconds1];


MCOSMTPSession * smtpSession = [[MCOSMTPSession alloc] init];
smtpSession = [[MCOSMTPSession alloc] init];


smtpSession.hostname = @"smtp.gmail.com";
smtpSession.port = 465;

smtpSession.username = email; //saved value

smtpSession.password=nil;

smtpSession.connectionType = MCOConnectionTypeTLS;
smtpSession.OAuth2Token = accessToken; //saved value
smtpSession.authType = MCOAuthTypeXOAuth2;



 smtpSession.checkCertificateEnabled=NO;


MCOMessageBuilder * builder = [[MCOMessageBuilder alloc] init];

MCOAddress *fromAddress = [MCOAddress addressWithMailbox:email];
MCOAddress *toAddress = [MCOAddress addressWithMailbox:self.to.text];
[[builder header] setFrom:fromAddress];
[[builder header] setTo:@[toAddress]];
NSString *htmlbody1=@"";

[[builder header] setSubject:@"Some subject"];
[builder setHTMLBody:htmlbody1];
MCOAttachment *attachment = [MCOAttachment attachmentWithContentsOfFile:self.filename];
[builder addAttachment:attachment];
[smtpSession setConnectionLogger:^(void * connectionID, MCOConnectionLogType type, NSData * data) {
    NSString *response = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSLog(@"Response %@",response);
}];
NSData * rfc822Data = [builder data];

MCOSMTPSendOperation *sendOperation = [smtpSession sendOperationWithData:rfc822Data];
[sendOperation start:^(NSError *error) {
    if(error) {
        NSLog(@"%@ Error sending email:%@", email, error);
    } else {
        NSLog(@"%@ Successfully sent email!", email);

    }
}];

`

0 个答案:

没有答案