Login with twitter in ios 7

后端 未结 1 653
悲&欢浪女
悲&欢浪女 2021-02-06 19:34

I am doing login functionality. In which -

  1. user will give twitter email id to login and if login gets succeeded, my app will navigate user to

相关标签:
1条回答
  • 2021-02-06 20:30

    First of all, you can not get user email address from twitter's API either using iOS7 framework or Twitter's Native API.
    If you want to get user email address you can ask user to enter it manually. That's what Twitter people say in their API Docs. For your Point 2 and 3 here is the sample code using iOS7 way

    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) // check Twitter is configured in Settings or not
    {
        self.accountStore = [[ACAccountStore alloc] init]; // you have to retain ACAccountStore
    
        ACAccountType *twitterAcc = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
    
        [self.accountStore requestAccessToAccountsWithType:twitterAcc options:nil completion:^(BOOL granted, NSError *error)
         {
             if (granted)
             {
                 self.twitterAccount = [[self.accountStore accountsWithAccountType:twitterAcc] lastObject];
                 NSLog(@"Twitter UserName: %@, FullName: %@", self.twitterAccount.username, self.twitterAccount.userFullName);
                 [self getTwitterEmail]; // here you can ask user to enter email address. Its up to you how you ask user about it. Either in alert View or in Text Field.
             }
             else
             {
                 if (error == nil) {
                     NSLog(@"User Has disabled your app from settings...");
                 }
                 else
                 {
                     NSLog(@"Error in Login: %@", error);
                 }
             }
         }];
    }
    else
    {
        NSLog(@"Not Configured in Settings......"); // show user an alert view that Twitter is not configured in settings.
    }
    
    0 讨论(0)
提交回复
热议问题