android – How to get twitter screen name in Firebase auth-ThrowExceptions

Exception or error:

Hi I am not sure how to get twitter screen name from getprovidersData() as it is returning a List and when I iterated the List it give data like

D/Twitter Data::
D/Twitter Data::

    List proData = mFirebaseUser.getProviderData();
    for (Object ui:proData
         ) {
        Log.d("Twitter Data:",ui.toString());

How will I get twitter use screen name from that.

Thank you!

How to solve:

This code is derived from the example provided in the documentation. Please try running it after you have signed in with Twitter to see if the display name is the screen name you are expecting.

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

if (user != null) {
    for (UserInfo profile : user.getProviderData()) {
        if (profile.getProviderId().equals(TwitterAuthProvider.PROVIDER_ID)) {
            // UID specific to the provider
            String uid = profile.getUid();

            // Name, email address, and profile photo Url
            String name = profile.getDisplayName();
            String email = profile.getEmail();
            Uri photoUrl = profile.getPhotoUrl();
            Log.i("DEBUG", String.format("uid=%s name=%s email=%s url=%s",
                    uid, name, email, photoUrl));


You need 4 things to get twitter user details including screen_name.

  1. Consumer Key
  2. Consumer Secret
  3. Access Token
  4. Token Secret

1 and 2 you can get from twitter app dashboard.

3 and 4 will be given in signInSuccessWithAuthResult callback function in authResult object when a user successfully signed in using firebase auth.
These 4 should go in header request for GET api call ->

more info on this:

To use in node.js app:

To test out using postman:

enter image description here

Leave a Reply

Your email address will not be published. Required fields are marked *