简体   繁体   中英

How to get profile URL of the logged in user with Twitter kit/Fabric iOS

I am using iOS Twitter Kit for implementing login mechanism with twitter in my iOS app. I have successfully installed twitter kit using Fabric. I am using following code to login and to get details of logged in user.

TWTRLogInButton *logInButton = [TWTRLogInButton buttonWithLogInCompletion:^(TWTRSession *session, NSError *error) {
    // play with Twitter session
    if (session) {
        NSLog(@"Twitter signed in as -> name = %@ id = %@ ", [session userName],[session userID]);

        /* Get user info */
        [[[Twitter sharedInstance] APIClient] loadUserWithID:[session userID]
                                                  completion:^(TWTRUser *user,
                                                               NSError *error)
        {
            // handle the response or error
            if (![error isEqual:nil]) {
                NSLog(@"Twitter info   -> user = %@ ",user);
            } else {
                NSLog(@"Twitter error getting profile : %@", [error localizedDescription]);
            }
        }];

    } else {
        NSLog(@"Twitter error signed in : %@", [error localizedDescription]);
    }
}];
logInButton.center = self.view.center;
[self.view addSubview:logInButton];

Using received TWTRUser *user object, I am able to access user info such as name, screen name, profile image url. Is there any way to get other user information such as user's profile page url, phone no etc?

TWTRLogInButton *logInButton = [TWTRLogInButton buttonWithLogInCompletion:^(TWTRSession *session, NSError *error) {
    // play with Twitter session
    if (session) {
        NSLog(@"Twitter signed in as -> name = %@ id = %@ ", [session userName],[session userID]);

        /* Get user info */
        [[[Twitter sharedInstance] APIClient] loadUserWithID:[session userID]
                                                  completion:^(TWTRUser *user,
                                                               NSError *error)
        {
            // handle the response or error
            if (![error isEqual:nil]) {
                NSLog(@"Twitter info   -> user = %@ ",user);
                NSString *urlString = [[NSString alloc]initWithString:user.profileImageLargeURL];
                NSURL *url = [[NSURL alloc]initWithString:urlString];
                NSData *pullTwitterPP = [[NSData alloc]initWithContentsOfURL:url];

                UIImage *profImage = [UIImage imageWithData:pullTwitterPP];


            } else {
                NSLog(@"Twitter error getting profile : %@", [error localizedDescription]);
            }
        }];

    } else {
        NSLog(@"Twitter error signed in : %@", [error localizedDescription]);
    }
}];
logInButton.center = self.view.center;
[self.view addSubview:logInButton];

As far as I can see in this link , the login action return 'ID' (numerical) also. You can use this Unique ID to get logged in user profile URL.

Snippet: https://twitter.com/intent/user?user_id=ID_FROM_RESPONSE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM