ios - 如何在 iOS 中获取推特个人资料图片?

标签 ios authentication twitter

我写了下面的代码:

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

NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:username, @"screen_name" ,[[controller.engine accessToken] secret]];

TWRequest *request = [[TWRequest alloc] initWithURL:url parameters:params requestMethod:TWRequestMethodGET];

[request performRequestWithHandler:
 ^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
     if (responseData) {
         NSDictionary *user = [NSJSONSerialization JSONObjectWithData:responseData
                                         options:NSJSONReadingAllowFragments
                                           error:NULL];

         NSString *profileImageUrl = [user objectForKey:@"profile_image_url"];

         NSLog(@"%@",profileImageUrl);
     }
 }];

但我总是以 Bad authentication 错误告终。我觉得我错过了什么。有人可以检查我的代码吗?或者提供任何检索 Twitter 用户个人资料图片的建议?

谢谢

最佳答案

您是否考虑过为此使用第 3 方 Twitter 引擎?我用过 FHSTwitterEngine取得了相当大的成功,并且似乎正在积极开发中。

要拉出个人资料图片,您可以这样做:

[[FHSTwitterEngine sharedEngine]permanentlySetConsumerKey:@"<consumer_key>" andSecret:@"<consumer_secret>"];
[[FHSTwitterEngine sharedEngine]showOAuthLoginControllerFromViewController:self
withCompletion:^(BOOL success) {
    if (success) {
        UIImage *profileImg = [[FHSTwitterEngine sharedEngine] getProfileImageForUsername:@"<username>" andSize:size];
    }
}];

关于ios - 如何在 iOS 中获取推特个人资料图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18917651/

相关文章:

ios - 并行多个快速动画不起作用

ios - 如何强制调用rendererForOverlay

amazon-web-services - Amplify 的 completeNewPassword 方法为用户数据抛出 TypeError

ios - AF 网络 2.0 : credentials not sent to authentication within 30 seconds of previous request

ios - 对用户隐藏 UIActivityViewController 中的字符串

ios - TextField 覆盖在 ScrollView 上 "Adjust to Fit"TextField 不起作用

ios - UIBackGround 模式和 iBeacons : app rejected

apache - 通过 AJP 将 REMOTE_USER 转发到 tomcat(例如,用于 shibboleth)

ios - 将项目从其他数组添加到 NSArray 时出现问题

python - 无效或过期的 token 。通过 Tweepy 请求新 token ?