basha
basha

Reputation: 617

How to get user details from twitter API in android application

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.

Upvotes: 2

Views: 1361

Answers (2)

Bhavya Gandhi
Bhavya Gandhi

Reputation: 507

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

Upvotes: 0

Safal Kumar Ghimire
Safal Kumar Ghimire

Reputation: 318

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

Upvotes: 1

Related Questions