title: Facebook API - different user ID's for each app?
body: <p>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 <strong>userId</strong> for a given user, to match it up with my DB. I'm using <strong>oauth.io</strong> to process the login, and return the values:</p>
  
  <pre><code>$('#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;
  });
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>'id' =&gt; '838605583',
  </code></pre>
  
  <p>..and then using the other app in my oauth.io (<a href="https://oauth.io" rel="noreferrer">https://oauth.io</a>) setup:</p>
  
  <pre><code>id  "10155167132970584"
  </code></pre>
  
  <p>Both for exactly the same user.</p>
  
  <p>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!</p>
  
  <p><strong>NOTE:</strong> A bit of info from Facebook, regarding this change:</p>
  
  <p><a href="https://developers.facebook.com/docs/apps/upgrading#upgrading_v2_0_user_ids" rel="noreferrer">https://developers.facebook.com/docs/apps/upgrading#upgrading_v2_0_user_ids</a></p>
  
  <blockquote>
    <p>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.</p>
    
    <p>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.</p>
    
    <p>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.</p>
    
    <p>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.</p>
    
    <p>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.</p>
    
    <p>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</p>
  </blockquote>
  
  <p>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</p>