Twitter Screen Name returning a null in Parse

Logging in via Twitter and trying to get the Users screen name. The screen name produces a null value each time. Any ideas?

PFUser *currentUser = [PFUser currentUser];
    [PFTwitterUtils logInWithBlock:^(PFUser *user, NSError *error) {
        if (!user) {
            NSLog(@"Uh oh. The user cancelled the Twitter login.");
            return;
        } else if (user.isNew) {
            twitterScreenName = [PFTwitterUtils twitter].screenName;
            NSLog(@"%@",[PFTwitterUtils twitter].screenName);
            NSString * requestString = [NSString stringWithFormat:@"https://api.twitter.com/1.1/users/show.json?screen_name=%@", twitterScreenName ];

                                        NSURL *verify = [NSURL URLWithString:requestString];
                                        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:verify];
                                        [[PFTwitterUtils twitter] signRequest:request];

                                        [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
                NSError *error;
                NSDictionary* result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
                if (!error) {

                   user.username =twitterScreenName;
                   user[@"name"]= result[@"name"];
                    user[@"profileDescription"] = result[@"description"];
                  user[@"imageURL"] = [result[@"profile_image_url_https"] stringByReplacingOccurrencesOfString:@"_normal" withString:@"_bigger"];
                    [user saveEventually];
                }
            }];
          [self performSegueWithIdentifier: @"username" sender: self];

        }

  • iOS 5 Attach photo to Twitter with Twitter API
  • Is it possible to bypass the tweet dialog and post directly to twitter?
  • How to make User logout from twitter fabric ios
  • Cannot Send Tweet popup appears
  • how to open Facebook app from url only if installed
  • iPhone- Twitter API GET Users Followers/Following
  • 3 Solutions Collect From Internet About “Twitter Screen Name returning a null in Parse”

    Here is how I do it:

    [PFTwitterUtils logInWithBlock:^(BOOL succeeded, NSError *error) {
        if ([PFTwitterUtils isLinkedWithUser:[PFUser currentUser]]) {
            NSURL *info = [NSURL URLWithString:@"https://api.twitter.com/1.1/account/settings.json"];
            NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:info];
            [[PFTwitterUtils twitter] signRequest:request];
            [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
                if (!!data) {
                    NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
                    NSString *userName = dict[@"screen_name"];
                    userName = [userName stringByReplacingOccurrencesOfString:@"Twitter:" withString:@""];
    
                    PFUser *user = [PFUser currentUser];
                    user[@"Twitter"] = userName;
                    [user saveEventually];
                } else {
                  //uh oh, no twitter response
                }
            }];
        } else {
            //uh oh, failed login
        }
    }];
    

    Try configuring this in the Twitter portal. It will give you options for which permissions your app has (meaning you might have to enable returning a username manually from within Twitter’s dashboard).

    - (IBAction)TWloginPress:(id)sender {
        [activityview setHidden:NO];
        [activityview startAnimating];
        [[Twitter sharedInstance] logInWithCompletion:^
         (TWTRSession *session, NSError *error) {
             if (session) {
                  [self signupUser:session.userName email:nil loggedinvia:@"TWITTER"];
             } else {
                 NSLog(@"error: %@", [error localizedDescription]);
                 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"There was some problem with signing you with twitter. Please try again." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alert show];
             }
         }];
    }