最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Facebook Graph API - User ID unique? - Stack Overflow

programmeradmin3浏览0评论

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/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 pletely different app but I'm new to the facebook api and looking to the experts for advice.

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/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 pletely different app but I'm new to the facebook api and looking to the experts for advice.

Share Improve this question asked Jun 1, 2016 at 3:51 mwilsonmwilson 12.9k9 gold badges62 silver badges102 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 17

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.

发布评论

评论列表(0)

  1. 暂无评论