2

I am doing an android app with TwitterLogin Integration using Twitter Api. Here I am not using any twitter 4j and fabric . I am able to get Twitter user name but unable to get Email Id. searched more for this issue, but got nothing with twitter api. I followed this twitterAPI to login

and this is my code

twitterLoginButton.setCallback(new Callback<TwitterSession>() {
                @Override
                public void success(Result<TwitterSession> result) {

                    System.out.println("=======twitterlogin success=======");

                    String username=result.data.getUserName();

                    getUsertwitteremail();
                }

                @Override
                public void failure(TwitterException exception) {
                    System.out.println("=======twitterlogin failure==========");
                }
            });

please someone help me to get the details including email.

basha
  • 587
  • 2
  • 6
  • 25
  • but I got this https://twittercommunity.com/t/how-we-can-get-email-address-with-users-detail-using-api/882/28 please check it – basha Jun 29 '17 at 06:00
  • Check this link. It will help you to get Email address of user. https://dev.twitter.com/twitterkit/android/log-in-with-twitter – AmmY Jun 29 '17 at 06:06

2 Answers2

1

First of all make sure Request email addresses from users is checked for your Twitter app Check out the code below and get the email

 mTwitterAuthClient.authorize(this, new com.twitter.sdk.android.core.Callback<TwitterSession>() {
            @Override
            public void success(Result<TwitterSession> twitterSessionResult) {
                TwitterSession session = TwitterCore.getInstance().getSessionManager().getActiveSession();
                TwitterAuthToken authToken = session.getAuthToken();
                String token = authToken.token;
                String secret = authToken.secret;
                long userId = session.getUserId();
                String userNa = session.getUserName();
                Log.d("twitter check", userNa + "  " + secret);

                mTwitterAuthClient.requestEmail(session, new Callback<String>() {
                    @Override
                    public void success(Result<String> result) {
                        Log.d("email", result.data);
                        // Do something with the result, which provides the email address
                    }

                    @Override
                    public void failure(TwitterException exception) {
                        // Do something on failure
                    }
                });
            }

            @Override
            public void failure(TwitterException e) {
                e.printStackTrace();
            }
        });
  • getting null response for email – basha Jun 29 '17 at 06:19
  • have you put this code on onActivityResult?? Also check the app secret as well as the token... and try again mTwitterAuthClient.onActivityResult(requestCode, resultCode, data); – Safal Kumar Ghimire Jun 29 '17 at 06:30
  • @basha . you need to request user email from your twitter application premissions dashboard, make sure you're activating that option, [follow this answer for an explanation](https://stackoverflow.com/a/47816326/4846859) – Biskrem Muhammad Dec 18 '17 at 23:13
  • but this answer only fetching username, id and email. i need full details about the user.. like firstname, lastname and gender? – Biskrem Muhammad Dec 18 '17 at 23:15
0

please enable permissions for email access form your twitter app console. from here https://apps.twitter.com/app/14057942/permissions enter image description here

Bhavya Gandhi
  • 507
  • 3
  • 10