How to get twitter profile picture in ios?

后端 未结 6 1850
悲哀的现实
悲哀的现实 2021-01-03 02:43

I wrote the following code:

NSURL *url = [NSURL URLWithString:@\"http://api.twitter.com/1.1/users/show.json\"];

NSDictionary *params = [NSDictionary diction         


        
6条回答
  •  没有蜡笔的小新
    2021-01-03 03:37

    this is what i have tried in past

    [PFTwitterUtils logInWithBlock:^(PFUser *user, NSError *error) {
        if (!user) {
            NSLog(@"Uh oh. The user cancelled the Twitter login.");
            [[NSNotificationCenter defaultCenter] postNotificationName:notificationUserLoginFailed
                                                                object:error];
            return;
        } else {
    
            // TODO find a way to fetch details with Twitter..
    
            NSString * requestString = [NSString stringWithFormat:@"https://api.twitter.com/1.1/users/show.json?screen_name=%@", user.username];
    
    
            NSURL *verify = [NSURL URLWithString:requestString];
            NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:verify];
            [[PFTwitterUtils twitter] signRequest:request];
            NSURLResponse *response = nil;
            NSData *data = [NSURLConnection sendSynchronousRequest:request
                                                 returningResponse:&response
                                                             error:&error];
    
    
            if ( error == nil){
                NSDictionary* result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
                _NSLog(@"%@",result);
    
                [user setObject:[result objectForKey:@"profile_image_url_https"]
                         forKey:@"picture"];
                // does this thign help?
                [user setUsername:[result objectForKey:@"screen_name"]];
    
                NSString * names = [result objectForKey:@"name"];
                NSMutableArray * array = [NSMutableArray arrayWithArray:[names componentsSeparatedByString:@" "]];
                if ( array.count > 1){
                    [user setObject:[array lastObject]
                             forKey:@"last_name"];
    
                    [array removeLastObject];
                    [user setObject:[array componentsJoinedByString:@" " ]
                             forKey:@"first_name"];
                }
    
                [user saveInBackground];
            }
    
            [[NSNotificationCenter defaultCenter] postNotificationName:notificationUserDidLogin
                                                                object:nil];
    
            return;
        }
    
    
    
    }];
    

提交回复
热议问题