ios - Twitter登录解析iOS

标签 ios objective-c twitter parse-platform

我正在建立一个Twitter iOS登录。尝试获取新用户的屏幕名称时,第一次登录时没有获取屏幕名称,而第二次登录时却获取了屏幕名称。我该如何做才能在第一次登录时获得屏幕名称?

这是我正在使用的代码:

[PFTwitterUtils logInWithBlock:^(PFUser *user, NSError *error) {
    if (!user) {
        NSLog(@"Uh oh. The user cancelled the Twitter login.");
        return;
    } else if (user.isNew) {
        NSLog(@"User signed up and logged in with Twitter!");

        NSLog(@"%@", [PFTwitterUtils twitter].screenName);
        [self performSegueWithIdentifier: @"hasUsername" sender: self];
    } else {
        NSLog(@"User logged in with Twitter!");
       NSLog(@"%@", [PFTwitterUtils twitter].screenName);
        [self performSegueWithIdentifier: @"hasUsername" sender: self];
    }     
}];

NSLog函数仅在首次登录时返回空值。

最佳答案

这是使用Twitter登录和解析时使用的内容:

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

从我的其他答复中复制:Twitter Screen Name returning a null in Parse

关于ios - Twitter登录解析iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29590292/

相关文章:

ios - 根据时间更改状态栏颜色

ios - 核心数据 NSFetchrequest 整数

javascript - URL变化无闪烁

django-allauth 和 twitter 集成 - 社交网络登录失败

objective-c - NSTimer 不会在 iPad 上失效,但在 iPhone 上可以正常工作

ios - 旋转后 UIImagePickerController 的状态栏和布局问题

ios - 核心数据 : suggestions for model design

objective-c - Objective C - [NSArray count] 上的 EXC_BAD_ACCESS 但看不到如何

iphone - 在构造函数中获取属性集

node.js - NodeJS 实际上使用 OAuth (Twitter)