Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 现在如何在iOS中获取twitter个人资料图片URL?_Objective C_Twitter_Xcode4.5 - Fatal编程技术网

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);
    }
}];

那个代码不起作用,工作得很好!