Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the Facebook user id picked up by Firebase different to the Facebook id associated with the same account in the Facebook Graph?

I have integrated Facebook authentication with Firebase into my website. I am using the Firebase JavaScript API.

The code I am using is lifted straight from the Firebase tutorial titled "User Login & Authentication" available here: https://www.firebase.com/docs/web/guide/user-auth.html

var myRef = new Firebase("https://#######.firebaseio.com");
var auth = new FirebaseSimpleLogin(myRef, function(error, user) {
    if (error) {
        // an error occurred while attempting login
        console.log(error);
    } else if (user) {
        // user authenticated with Firebase
        console.log("User ID: " + user.id + ", Provider: " + user.provider);
    } else {
        // user is logged out
    }
});
auth.login("facebook");

This all works perfectly well, logging the correct information.

However, the id that is logged (i.e. the user id that visible in the data in the Firebase dashboard) is different to the Facebook id I get through Facebook Graph.

With Firebase, I get a 17-digit user id. With Facebook Graph (https://developers.facebook.com/tools/explorer?method=GET&path=me%3Ffields%3Did%2Cname&version=v2.0), I get a 9-digit user id.

This means that I can't use Firebase to login, grab the Facebook id and make requests through Facebook Graph - the user ids for the same user are different.

Why does this difference exist? How can I use Firebase to get the same Facebook id that appears in Facebook Graph?

like image 307
Nate Avatar asked Oct 01 '22 03:10

Nate


1 Answers

Facebook recently introduced version 2.0 of their Open Graph. With that came a lot of changes. One of them is the user ID returned by Facebook to Facebook applications. Instead of every app receiving a user's global Facebook ID, each app now receives what they call an "app-scoped ID." This means that every app will receive a different user ID for user X even though each unique ID still maps to user X. If you need to be able to map a user across multiple apps, you can use their Business Mapping API. Ultimately, this was a change Facebook made that we at Firebase have no control over.

If you are getting a 17-character ID from Simple Login, it probably is because your Facebook app was created before the change to Facebook login v2 happened (a little over a month ago). I see in your Open Graph Explorer request that it is using v2. But with Simple Login we are using a mixture of v1 and v2 depending on when your Facebook app was created. We are working on adding an option for you to decide what version of the Facebook Open Graph API you want to use, but have not added that yet. If you want to use v2 at this point, you just have to create a new Facebook app and everything should work. If you want to stay with v1, be aware that Facebook will stop supporting it in around 10 months.

Search for "App-scoped User IDs" on this page for their official changelog information.

like image 114
jwngr Avatar answered Oct 19 '22 00:10

jwngr