Facebook API - 每个应用程序的用户 ID 不同?

Facebook API - different user ID's for each app?

我目前正在开发一个移动应用程序,因此我需要一个专门用于此目的的新应用程序。看起来很愚蠢的是,Facebook 决定为每个应用程序使用不同的 "user ids"。除了看不到这一切的意义之外,我对如何为给定用户提取相同的 userId 以将其与我的数据库匹配感到困惑。我正在使用 oauth.io 处理登录,return 值:

$('#facebook-login').click(function() {
    $('#ajax_spinner_wrapper').show();
    OAuth.initialize('CmRGYdnRMWM2ZrOb7M1Nf1_T57o');
    OAuth.popup('facebook').done(function(result) {
        //console.log(result)
        result.get('/me').done(function(data) {
            //todo with data
            console.log(data);

            $.post('https://steampunkjunkies.net/cgi-bin/mobi_login.cgi', { action: 'store_session', what: 'facebook', user: data.id }, function(result) {
                $('#ajax_spinner_wrapper').hide();
            });
        }).fail(function(err) {
            //todo with err
            console.log("Hit an error?");
        });


    })
    .fail(function (err) {
        alert("oops, we got an error!");
        console.log(err);
        $('#ajax_spinner_wrapper').hide();
    });

    return false;
});

但问题是,它在每个应用程序中为我提供了完全不同的 ID。这是我通过基于网络的方式获得的结果:

'id' => '838605583',

..然后在我的 oauth.io (https://oauth.io) 设置中使用其他应用程序:

id  "10155167132970584"

两者都针对完全相同的用户。

有什么方法可以关联这些 ID,以便我可以将它们匹配在一起吗?令人惊讶的是,Facebook 认为这样的事情不会成为问题!

注意: 来自 Facebook 的一些关于此更改的信息:

https://developers.facebook.com/docs/apps/upgrading#upgrading_v2_0_user_ids

Facebook will begin to issue app-scoped user IDs when people first log into an instance of your app coded against v2.0 of the API. With app-scoped IDs, the ID for the same user will be different between apps.

No matter what version they originally used to sign up for your app, the ID will remain the same for people who have already logged into your app. This change is backwards-compatible for anyone who has logged into your app at any point in the past.

If you're not mapping IDs across apps, then no code changes should be required. 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. Learn more about implementing cross-promotions.

For users who have not logged into your app, the user ID may change depending on the version of the API that you call. In v1.0 of the API users who have not logged into your app will be referred to by their original Facebook user ID, whereas in v2.0 they will be referred to by an app-scoped ID.

We've added new API endpoints that allow you to tag and invite friends who don't use your app. These APIs return tokens which may be used to generate custom interfaces for tagging and invitations. Those tokens aren't meant to be cachable and we make no guarantees that they will be stable beyond 24 hours from the time the API response containing them was received. They aren't the same as either the IDs used on data for people not logged into your app nor the same as the app-scoped IDs.

Users can check their app-scoped IDs for each app they've installed in the app's Edit Settings dialog. Make sure users of your app know how to find it when they contact you with support queries

我真的不明白他们的逻辑。为每个用户设置一个唯一标识符更有意义,可用于针对任意数量的应用程序对其进行验证。在我的例子中,有人登录到我们基于网络的应用程序,然后他们也想登录到移动应用程序 - 但它有一个不同的用户 ID,所以没有办法 link 将两者放在一起!呃

嗯,这是很老的新闻了。自 2014 年 4 月 30 日以来一直如此。随着图表 API v2.0 的推出,FB 还推出了专为您的用例设计的业务映射 API。

您不会收到 一个 用户 ID,但您会收到一个 token_for_business:

This returns a string which is the same for this person across all the apps managed by the same Business Manager.

LoginManager.logInWithReadPermissions(['email']).then((result) => {
          if (result.isCancelled){
            //console.warn("Login is canceled");
          } else {
             AccessToken.getCurrentAccessToken().then((data) =>{
             const responseInfoCallback = (error, result) => {
                if (error) {

                } else {
                    //you can pick data.userID  and data.applicationID
                    //To getting unique id of user by application
                    //I think you can use (data.userId + data.applicationId) as the id
                    //For getting profile you can use result.name, result.id (it likes data.userId)
                    //Token is available in data.accessToken

                }
              }
              const infoRequest = new GraphRequest(
                '/me',
                {
                  accessToken: data.accessToken,
                  parameters: {
                    fields: {
                      string: 'email, name, gender, picture,cover, id'
                    }
                  }
                },
                responseInfoCallback
              );
              new GraphRequestManager().addRequest(infoRequest).start()
        })
          }
        }, (error) => {
          console.warn(error)
        });