Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Graph API - User ID unique?

I am trying to figure out a good way to store a unique ID for a user in my app. I am using facebook login for user management and have a class for the user:

function FacebookUser(userObj) {
    if (userObj) {
        this.name = userObj.name;
        this.id = userObj.id;
        this.picture = userObj.picture.data.url;
        this.isLoggedIn = true;
    } else {
        this.name = 'Login';
        this.id = 0;
        this.picture = '';
        this.isLoggedIn = false;
    }
}

Basically, I have a service in angular that handles the Facebook login:

.service('facebookService', function () {

        this.getFacebookUser = function (callback) {
            $.getScript("//connect.facebook.net/en_US/sdk.js", function () {
                var appId = "12312312313123";
                FB.init({
                    appId: appId,
                    status: true,
                    cookie: true,
                    xfbml: true,
                    version: 'v2.4'
                });

                FB.getLoginStatus(function (response) {
                    if (response.status == 'connected') {
                        FB.api('/me?fields=picture,name,email', function (data) {
                            callback(new FacebookUser(data));
                        })
                    } else {
                        FB.login(function (response) {
                            FB.api('/me?fields=picture,name,email', function (data) {
                                callback(new FacebookUser(data));
                            })
                        });
                    }
                })
            });
        }

    })

What I'm trying to figure out is what the unique identifier is. I would like to just use the email address of the user since it's guarenteed to be unique but don't want to ask for extra permissions. Originally, I wanted to use the id field but I'm unclear on if the id is going to ever change or not. In the facebook documentation, they explain the id field as such:

The id of this person's user account. This ID is unique to each app and cannot be used across different apps. Our upgrade guide provides more information about app-specific IDs

According to this, the ID is unique to the app and cannot be used across different apps. However, I am trying to get a little more clarity here. If one user logs into the app today and then again in a couple months, will their ID be the same (if it's the same app) or will it change? Secondary question would be that if/when I make a change and get a new app id, will the ID be the same or change? It's technically still the same app, just a different version. My assumption is that since it's a different appId, facebook thinks it's a completely different app but I'm new to the facebook api and looking to the experts for advice.

like image 956
mwilson Avatar asked Jun 01 '16 03:06

mwilson


1 Answers

I'm not an expert, but I will try to answer your questions.

If one user logs into the app today and then again in a couple months, will their ID be the same (if it's the same app) or will it change?

As long as the App ID is the same, the user ID will not change, even between logins, no matter how long in between.

Secondary question would be that if/when I make a change and get a new app id, will the ID be the same or change?

A new App ID means a different App, which means the user ID will change. But if you get a new App ID and need to access the same user, you can use facebook's Business Mapping API.

Excerpt from facebook docs:

If you need to map the same user IDs across multiple apps or run cross-app promotions, we've added a new API called the Business Mapping API. This lets you map a logged-in user's IDs across apps as long as those apps are all owned by the same business.

like image 183
Trapsilo Bumi Avatar answered Sep 28 '22 20:09

Trapsilo Bumi