简体   繁体   English

Twitter数字:如何检查用户是否已注册

[英]Twitter Digits : how to check if the user is already registered

I am experimenting with Digits API by Twitter for registering users on my Android application. 我正在通过Twitter试验Digits API,以便在我的Android应用程序上注册用户。 Currently in my launching activity I display a button( com.digits.sdk.android.DigitsAuthButton ) that asks for users to enter their phone number so that a confirmation code could be sent. 目前在我的启动活动中,我显示了一个按钮( com.digits.sdk.android.DigitsAuthButton ),要求用户输入他们的电话号码,以便发送确认码。 Once they enter the confirmation code and are authenticated, I receive a user_id in the callback method. 一旦他们输入确认码并进行身份验证,我就会在回调方法中收到user_id

Now, next time if I click on the same button in the launching activity it doesn't display the option to enter the phone number and just returns back the same user_id which was already registered. 现在,下次如果我点击启动活动中的相同按钮,它不会显示输入电话号码的选项,只返回已经注册的相同user_id

I want to replicate this same thing in my Java code without that extra click of the com.digits.sdk.android.DigitsAuthButton button. 我想在我的Java代码中复制同样的东西,而无需额外点击com.digits.sdk.android.DigitsAuthButton按钮。 I had a look at some samples and they use the following statement to verify the same: 我查看了一些示例,他们使用以下语句来验证相同的内容:

if (Digits.getSessionManager().getActiveSession() != null) { ... }

Is this sufficient or should I use sharedPreference to store the returned user_id with the phone number too ? 这是否足够或者我应该使用sharedPreference来存储返回的user_id和电话号码吗?

Update 更新

Personally i'm using sharedpreference it works well for me.. 我个人使用sharedpreference它对我来说很好..

as for handling "change in phone number later on" you can create a log out Button to turn a preference from true to false. 至于处理“稍后更改电话号码”,您可以创建一个注销按钮,将preference从true转为false。

Or 要么

you can check change in phone number: 你可以查看电话号码的变化:

TelephonyManager tMgr =     (TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
String mPhoneNumber = tMgr.getLine1Number();

//Required Permission:

<uses-permission android:name="android.permission.READ_PHONE_STATE"/> 

I know its late but may be helpful for a beginner.To verify that the session is already active, please put this code in your onCreate of that activity in which Digits phone number verification button is initialised: 我知道它很晚但可能对初学者有帮助。要验证会话是否已激活,请将此代码放入您初始化Digits电话号码验证按钮的活动的onCreate中:

    TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
            Fabric.with(this, new TwitterCore(authConfig), new Digits.Builder().build());
    if (Digits.getActiveSession() != null) {
                Intent ss = new Intent(CurrentActivity.this, SecondActivity.class);
                startActivity(ss);
                finish();
            }

And whenever you want to retrive phone number then call : 无论何时您想要转发电话号码,请致电:

String phone = Digits.getActiveSession().getPhoneNumber();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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