通过 Twitter 登录并尝试获取用户的屏幕名称。每次都会产生 null 值。有什么想法吗?
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];
}