Search code examples
firebasetwitterfirebase-authentication

Firebase Auth: Is it possible to see user's Twitter ID?


I have just implemented the Twitter login to my Firebase web app. When the user successfully login, I'd like to see the user's Twitter ID (to enable Twitter-based communication among users).

According to the document (https://firebase.google.com/docs/auth/web/manage-users), the provider specific information is under providerData of the user info.

Under the providerData, I see the following

displayName: "Satoshi Nakajima" (as I expected)
email: null (as I expected)
phoneNumber: null (as I expected)
photoURL: "https://abs.twimg.com/..." (as I expected) 
providerId: "twitter.com" (of course)
uid: "1129128..." (what is this?)

The uid seems like a unique id, but it is different from the Twitter ID we usually use, such as @snakajime (which is mine).

I am wondering why I don't see the Twitter id here. Am I missing something? Is there any API to get the Twitter ID from this strange uid?


Solution

  • You can actually get it immediately after sign-in, via AdditionalUserInfo.

    Here is an example with the web API:

    firebase.auth().signInWithPopup(new firebase.auth.TwitterAuthProvider())
      .then((userCredential) => {
        // Get the Twitter screen name.
        console.log(userCredential.additionalUserInfo.username);
      })
      .catch((error) => {
        // An error occurred.
      });