ios – Twitter屏幕名称在Parse中返回null

通过Twitter登录并尝试获取用户屏幕名称.屏幕名称每次都会生成一个空值.有任何想法吗?
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];

        }

解决方法

我是这样做的:
[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,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
    }
}];

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...