2013-06-28 138 views

回答

2

这是做

  NSDictionary * resp = [NSJSONSerialization JSONObjectWithData:responseData 
                 options:0 
                 error:&jsonError]; 


      self.strUsername = [resp objectForKey:@"screen_name"]; 
      NSString * strPictureURL = [resp objectForKey:@"profile_image_url"]; 
      strPictureURL = [strPictureURL stringByReplacingOccurrencesOfString:@"_normal" withString:@""]; 
      self.strPictureURL = strPictureURL; 
+2

这段代码缺少许多组件。 – AddisDev

+0

完美运作! –

1

您需要设置

NSString * strPictureURL = [NSString stringWithFormat:@"https://api.twitter.com/1.1/users/profile_image?screen_name=%@&size=bigger",strUsername.RobustURLEncodedString]; 

,而不是第1版,使用1.1版

+1

代码https://api.twitter.com/1.1/users/profile_image?screen_name=teguh123&size=bigger不起作用。 –

3

可以使用Fabric Twitter library的新途径。

Configuration是很容易的:

[[Twitter sharedInstance] startWithConsumerKey:@"_key_" consumerSecret:@"_secret_"]; 
[Fabric with:@[[Twitter sharedInstance]]]; 

之后,它只需使用:

[[Twitter sharedInstance] logInWithCompletion:^(TWTRSession *session, NSError *error) { 
    if (session) { 
     NSString *userID = [Twitter sharedInstance].sessionStore.session.userID; 
     TWTRAPIClient *client = [[TWTRAPIClient alloc] initWithUserID:userID]; 
     [client loadUserWithID:userID completion:^(TWTRUser *user, NSError *error) { 
      NSLog(@"Profile image url = %@", user.profileImageLargeURL); 
     }]; 
    } else { 
     NSLog(@"error: %@", error.localizedDescription); 
    } 
}]; 
相关问题