Facebook oauth unified scoped id across apps in same business - facebook

I have two facebook apps in the same business.
I want to get same scoped ids for both apps when users are logging in (because I use the same database).
I've read the facebook upgrade guide, but I don't get how to use the token_for_business to get same id when the user is logged.
Graph api returns different tokens for business for every app (which is strange).
The only useful thing so far is the /me/ids_for_business call to get list of the user scoped IDs for every busines..but it only returns them if they were logged at least 1 time..
My second app is new and if user logs in to it (without logging in to the first app) I can't get his first app ID to store and use it.
Thanks

There will always be differend app-scoped user ids per app. That's the whole purpose of them.
Have you followed the steps at
https://developers.facebook.com/docs/apps/business-manager#create-business and/or
https://developers.facebook.com/docs/apps/business-manager#update-business
If so, according to the docs, the field token_for_business of the user should contain
A token that is the same across a business's apps. Access to this token requires that the person be logged into your app. This token will change if the business owning the app changes

Related

How to check if Facebook user is the App Admin

Using Facebook API for FB Login, how is possible to know if the user who authorized my application is the application's admin (owner)?
The old days FB return the real FB user id, so it was easy to compare it. Now it returns a number which is not the real FB profile id.
Thank you
The old days FB return the real FB user id, so it was easy to compare it. Now it returns a number which is not the real FB profile id.
That’s called app-scoped user id.
You will have to use that one to identify users within your app. So you need to get your admin user’s app-scoped id once after logging in as that user, and store it somewhere for future comparison.
There is also the /{app-id}/roles endpoint, which you can use to query which users have which role in your app. But that uses app-scoped user ids as well.
If you have multiple apps connected to a business, you can also use the User Ids For Apps endpoint to be able to match app-scoped user ids across different apps. (You will still have to use the app-scoped id for one of your “main” apps to compare against though; the global user id is not available at all any more via API / to 3rd-party apps.)

Facebook login for web and device generate different uid for same user

We are trying to update Facebook login for a device and found out different uid generated while login via PC browser and device login method. The uid generated by browser can get user feeds, but it return empty for uid generated by device login. Does anyone know why there is different uid for same user?
It's by design so that unrelated apps can't correlate their users.
Straight from the upgrade docs, emphasis mine;
App-scoped 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.

Facebook app scoped user id's temporary

I want to see who is going to a Facebook event, so I use the API to get the attendees. The users I get have an app scoped user id.
But here is the thing: sometimes the same user gets a different App Scoped User Id. So for example, the user John Doe first has an app scoped user id of 1000000, and a week later it is 2000000.
I get redirected to the same John Doe profile when I visit these urls:
facebook.com/app_scoped_user_id/1000000
facebook.com/app_scoped_user_id/2000000
Are these app scoped user ids temporary ids?
Edit:
This is the API call I use to get the event attendees:
https://graph.facebook.com/v2.3/EVENT_ID_HERE/attending?access_token=app_id|app_secret
App Scoped IDs are definitely not temporary if the user authorized your App. If the same user gets a different App Scoped ID, then i assume it´s because he is did NOT authorize your App. It makes sense, because non-authorized users should not be stored. If you think that this is a bug, you should file a report here: https://developers.facebook.com/bugs/

Facebook app - Test User ID changes after user first logins the app

I'm building an app that allows user to search for other Facebook users (using the search node on the Graph API that looks something like: search?q=T&type=user&limit=10 for users starting with T) and perform a certain 'pending' operation on those users, so when those users first connect to my app they will know someone performed a certain 'pending' operation on them.
Now, when those users first logs in my app their ID changes (at least for the Test users).
If this would happen to normal users as well this will pretty much not allow me to identify the users which had 'pending' operations on them.
If so, how can identify users without them logging in if their ID changes after login?
Final Answer:
I have opened a Facebook bug about it:
https://developers.facebook.com/bugs/1531594233745476
It seems like the ID's on the search API are not scoped for the app and are just global ID's until the user logins my app (which will eventually change his ID to the scoped one) this means that there is no option to detect scoped user and non scoped one. I think that the search node for users is really useless then.
If you call /v2.0/search?q=T&type=user, the IDs returned will be the same as when the user logs into your app - as long as your app invokes the login dialog also using v2.0 in the URL.
In v2.x, a person's ID is always consistent. However, if parts of your app are calling v1.0 and others calling v2.x, a person's ID will change unless they have logged into your app, in which case it will be the same between both versions.
If you're using Test Apps, the IDs between your production and test app should match - the exception is where the same user logged into the prod app using v1 and the test app using v2.
The simplest way to remove this inconsistency is to convert all your API calls across your prod app and all Test Apps to call v2.x.

How do we use user access token to stay logged on to my FB canvas site even though another FB user is logged in through the original website?

My scenario is somewhat like this: A user logs into my website with his FB credentials. I capture his ID and the FB access token (say, a long-lived access token). He exits my website, and returns back later. However, this time, his browser has FB open with a different ID. Would I be able to load facebook details of this old id (with which he had registered on my site) using the stored access tokens? Is it possible, or would it result in a clash between the old and the existing FB id?
Correct me if I'm wrong, but he/she should stay logged into your website, regaurdless if his authID changes.
First of all, why would you want to do that? Since Facebook does not allow multiple user accounts for one and the same person, the only case where this would normally come into play is when another user is using my computer/browser – and why would I want you to read my info while that other person is using my device …?
Second of all, as long as the first user is still considered logged in to your site, it makes not much difference. But lets say some client-side method is called that updates the cookie information, then that’s where trouble might start. You might still be able to read the old user’s info, since you have his valid access token – but you’d have to use that token in your requests explicitly, and also address the account specifically, since the Graph API’s /me would point to the new user.
But as I said, I can hardly imagine a real, practical use case here …