Objective c 现在如何在iOS中获取twitter个人资料图片URL?
我曾经这样做过:Objective c 现在如何在iOS中获取twitter个人资料图片URL?,objective-c,twitter,xcode4.5,Objective C,Twitter,Xcode4.5,我曾经这样做过: NSString * strPictureURL = [NSString stringWithFormat:@"https://api.twitter.com/1/users/profile_image?screen_name=%@&size=bigger",strUsername.RobustURLEncodedString]; 这已经不起作用了。Twitter关闭该API。嗯,我已经通过认证了。那么我怎么知道呢?您需要设置 NSString * strPictu
NSString * strPictureURL = [NSString stringWithFormat:@"https://api.twitter.com/1/users/profile_image?screen_name=%@&size=bigger",strUsername.RobustURLEncodedString];
这已经不起作用了。Twitter关闭该API。嗯,我已经通过认证了。那么我怎么知道呢?您需要设置
NSString * strPictureURL = [NSString stringWithFormat:@"https://api.twitter.com/1.1/users/profile_image?screen_name=%@&size=bigger",strUsername.RobustURLEncodedString];
用1.1版代替1版,这是一种新的方法
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;
你可以用
这很容易:
[[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);
}
}];
那个代码不起作用,工作得很好!