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
    }
}];

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...