Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm currently working on a mobile app, and as such I need to have a new app specifically for this purpose. The stupid thing it seems, is that Facebook have decided to use different "user ids" for each app. Apart from not seeing the point in this what-so-ever, I'm baffled as to how I can extract the same userId for a given user, to match it up with my DB. I'm using oauth.io to process the login, and return the values:

$('#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;
});

The problem though, is that it gives me totally different Id's in each app. Here is what I get with my web-based one:

'id' => '838605583',

..and then using the other app in my oauth.io (https://oauth.io) setup:

id  "10155167132970584"

Both for exactly the same user.

Is there some way to correlate these Id's, so I can match them together? Its amazing that Facebook didn't think that something like this would be an issue!

NOTE: A bit of info from Facebook, regarding this change:

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

I really don't get their logic. It makes much more sense having a unique identifier for each user, which can be used to verify it against any number of apps. In my case, someone logs into our web-based app, then they also want to log into the mobile one - but its got a different user ID, so there is no way to link the 2 together! Eugh

like image 633
Andrew Newby Avatar asked Jan 22 '15 10:01

Andrew Newby


People also ask

How do I get my Facebook API user ID?

The simplest way to get a copy of the User Profile object is to access the /me endpoint: FB. api('/me', function(response) { }); This will this will return the users name and an ID by default.

What is app scoped ID?

When a person uses Facebook Login on a website or a mobile app, an ID is created for the specific Facebook app, which is called app-scoped ID. When a person interacts with a business via Messenger, an ID is created for the specific Page associated with the bot in Messenger, which is called Page-scoped ID.

What is PSID Facebook?

PSID is a page-scoped ID for every contact in your Contacts that Facebook creates to handle different communication channels. It's common for a business to use multiple channels to communicate with its customers, e.g., a website, a mobile app, and Messenger.


1 Answers

Well, this is very old news. It's been like that since April 30th 2014. With the introduction of the graph API v2.0, FB also introduced the Business Mapping API, which is designed for your use case.

You won't receive one user id, but you'll receive a token_for_business:

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

See

  • https://developers.facebook.com/docs/apps/for-business#field
  • https://developers.facebook.com/docs/apps/for-business#api
  • https://developers.facebook.com/docs/apps/business-manager#create-business
like image 130
Tobi Avatar answered Sep 20 '22 17:09

Tobi