2

我曾经这样做:

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

https://api.twitter.com/1/users/profile_image?screen_name=username&size=bigger

那不再起作用了。Twitter 关闭了该 API。好吧,我已经通过了身份验证。那我怎么知道?

4

3 回答 3

3

您可以使用Fabric Twitter 库

配置非常简单:

[[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);
    }
}];
于 2015-11-07T20:02:13.467 回答
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;
于 2013-07-03T05:42:56.937 回答
1

你需要设置

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

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

于 2013-06-28T12:26:05.460 回答