Friday, July 1, 2016

Sharing user’s facebook account information in multiple apps / family of apps

If you are a developer who has multiple apps or portals which supports facebook login, then you may want to share user information across these apps. One possible example is game developers with multiple gaming apps wanting to get the users information provided for another app in same game family.Say you want to fetch the user's preference for one game and reuse it for your new game. If the user preference is stored against user's facebook  Id then this API will enable you to find the facebook Id of the user in your old game.

Facebook’s solution for this requirement is ids_for_business API. Using this API you can access user data of multiple apps, provided that both the apps are added to same business.


Sample request

Response
{
  "data":[
     {
        "id":"1041973262545425",
        "app":{
           "category":"Education",
           "link":"https://www.facebook.com/games/?app_id=20245051577740251",
           "name":"My App1",
           "id":"2024505157774025"
        }
     },
     {
        "id":"840774482665280",
        "app":{
           "category":"Utilities",
           "link":"https://www.facebook.com/games/?app_id=20245051577740252",
           "name":My App2 ",
           "namespace":"myapp",
           "id":"131285656905950"
        }
     }
  ],
  "paging":{
     "cursors":{
        "before":"MjAyNDUwNTE1Nzc3NDAxNwZDZFX",
        "after":"MTMxMjg1NjU2OTA1OTN24"
     }
  }
}

As you can see in the response both the app’s user details are available, now you can use this information in any of the apps under the same business.

Here are steps to use ids_for_business API
  1. Add all your apps to business. This has to be done from facebook developer console.
  2. Fetch user id for the current app using graph api
  3. Invoke the ids_for_business API with the retrieved userId to get information of the user in all the apps under business