从iOS中的Twitter获取用户个人资料详细信息(尤其是电子邮件地址) [英] Get user profile details (especially email address) from Twitter in iOS

查看:503
本文介绍了从iOS中的Twitter获取用户个人资料详细信息(尤其是电子邮件地址)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是根据用户的Twitter帐户获取用户的详细信息。首先,让我解释一下我想做什么。

I am aiming to get a user's details based on his/her Twitter account. Now first of all, let me explain what I want to do.

在我的情况下,用户将看到注册的选项使用Twitter帐户。因此,基于用户的Twitter帐户,我希望能够获取用户详细信息(例如电子邮件ID,姓名,个人资料图片,出生日期,性别等)并将这些详细信息保存在数据库中。现在,很多人可能会建议我使用 ACAccount ACAccountStore ,这是一个提供访问,操作界面的类,并存储帐户。但在我的情况下,即使用户尚未在iOS设置应用中为Twitter配置帐户,我也想要注册用户。我希望用户导航到Twitter的登录屏幕(在Safari中或在应用程序本身中,或使用任何其他替代方案)。

In my case, user will be presented an option to Sign-up with Twitter account. So, based on user's Twitter account, I want to be able to get user details (e.g. email-id, name, profile picture, birth date, gender etc..) and save those details in database. Now, many people will probably suggest me to use ACAccount and ACAccountStore, a class that provides an interface for accessing, manipulating, and storing accounts. But in my case, I want to sign up user, even if user has not configured an account for Twitter in iOS Settings App. I want user to navigate to login screen of Twitter (in Safari or in App itself, or using any other alternative).

我还提到了具有API的Twitter文档列出此处。但是我很困惑应该如何向用户呈现登录屏幕以登录Twitter帐户以及如何获取个人资料信息。我应该使用 UIWebView ,还是将用户重定向到Safari或采用其他方式?

I have also referred the documentation of Twitter having API list here. But I am a lot confused how user should be presented a login screen to log into the Twitter account and how I will get profile information. Should I use UIWebView, or redirect user to Safari or adopt another way for that ?

推荐答案

Twitter为此提供了一个漂亮的框架,您只需将其集成到您的应用中。

https://dev.twitter.com/twitter-kit/ios

它有一个简单的登录方法: -

// Objective-C
TWTRLogInButton* logInButton =  [TWTRLogInButton
                                     buttonWithLogInCompletion:
                                     ^(TWTRSession* session, NSError* error) {
    if (session) {
         NSLog(@"signed in as %@", [session userName]);
    } else {
         NSLog(@"error: %@", [error localizedDescription]);
    }
}];
logInButton.center = self.view.center;
[self.view addSubview:logInButton];

这是获取用户个人资料信息的过程: -

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

我认为您可以从Twitter套件教程中找到休息,它还可以通过以下方式请求用户的电子邮件:调用TwitterAuthClient#requestEmail方法,传入有效的TwitterSession和Callback。

I think rest you can find from Twitter Kit Tutorial, it also allows to request a user’s email, by calling the TwitterAuthClient#requestEmail method, passing in a valid TwitterSession and Callback.

这篇关于从iOS中的Twitter获取用户个人资料详细信息(尤其是电子邮件地址)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆