Get Facebook profile URL from app-scoped user ID - facebook

A Facebook user's profile URL is http://facebook.com/USER_ID. However, with an app-scoped user ID, http://facebook.com/APP_SCOPED_USER_ID doesn't redirect to the user's profile page. How can I reach an user's profile page using just an app-scoped user ID?

Use the link field of the user object. This will look like the following:
https://www.facebook.com/app_scoped_user_id/{app_scoped_user_id}/

The URL - https://www.facebook.com/app_scoped_user_id/{app_scoped_user_id}/ - is access limited, only X request can be made on Y period of time from an account.
I did build a tool to crawl facebook's username base on app-scoped uid, by making a request to that scoped uid profile, I can parse the redirect header to find out the username.
The access limitation makes me suck. :(

You can use url format:
http://fb.com/app_scoped_user_id/{app_scoped_user_id}
example
http://fb.com/app_scoped_user_id/10101640953722381
If you want to get real facebook id from app scoped user id: https://stackoverflow.com/a/34450491/2181069

Tested that the above answer: https://www.facebook.com/app_scoped_user_id/{app_scoped_user_id}/ works for new user that connect to your app after migration.
As stated in FB documentation, existing connected users will continue to return the global ID. And it seems that https://www.facebook.com/app_scoped_user_id/{existing_user_global_id}/ won't work.
Thus, need to differentiate between existing and new user and use the global url (https://www.facebook.com/{user_global_id}) and app-scoped URL accordingly. Kind of tedious...

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.)

How to get the FacebookUserId with graph api explorer?

With this URL: /v2.2/me?fields=id, I can retrieve the user's id. (with the user's token of course)
But I noticed that it doesn't correspond to its FacebookUserId thanks to this link.
My goal is to reach the profile user through my Cordova app using this url scheme:
fb://profile/facebookUserId
since fb://profile/id does not work for every user...
What is this distinct id?
If you have an app-scoped User ID, you can use the following URL scheme to link to his/her profile
https://www.facebook.com/app_scoped_user_id/{app_scoped_id}/
where {app_scoped_id} is the numeric app-scoped User ID.
See:
https://developers.facebook.com/docs/graph-api/reference/v2.2/user/#fields

Getting a user's ID using Facebook's Graph API

Is it possible to get the ID (Facebook Graph API) of a user who is currently logged in, without any access tokens?
If not, then how do I get new access tokens every time a user visits my page?
You will need to init the Facebook Javascript SDK and the user will have to have authorized your app at least one time. After that when the user visits your page as long as they are logged into Facebook you'll have access to the id and can retrieve it using
FB.getLoginStatus
the response will contain the information you're looking for.
Check this blog post for more details on setting up the FB init and the initial login.
https://developers.facebook.com/blog/post/525/
You can check the facebook ID using their username
http://graph.facebook.com/radrivan
You can use the javascript sdk to get their accesstoken and let them allow your app.
https://developers.facebook.com/docs/facebook-login/login-flow-for-web/v2.2

Get Facebook User Id of my website visitors w/o auth

Is there any way to get the Facebook User Id of visitors in my website by using the FB API, but without need to ask them to authenticate my Facebook app?
All I need is some facebook-related-identifier, it does not even have to be the User Id, but any kind of identifier that can relate the user to a facebook profile.
Ideas?
If the user does not explicitly authorize you to get some private data from his Facebook account (included his Facebook ID), you can not get them.
I cannot think of a way to get the Facebook ID without the authorization of the user.
Hope that helps.

Getting Facebook Details

how can i get a facebook user's info like name, country, etc without making him login using fb connect, etc if i already know his facebook id?
I mean can i use the php facebook client to get those details without prompting for login if i already know the facebook id?
Thanks in advance :)
You can't get that information with just a facebook id unless the person who the information belongs to made that information public (which almost noone has).
The only solution I see is to ask your users for the extended permission "offline_access".
As far as I know you can only do this from within a facebook application or through the Facebook Connect javascript library (so not with the PHP library for instance).
This means that you will have to ask users to login at facebook through fb:connect atleast once, ask for offline access and store the facebook sessionKey in your local database.
Because you have offline access now, the facebook sessionKey won't expire and you can login serverside without the user being present.
This is how I implemented the php server side after attaining the permanent session:
$this->fb = new Facebook($settings["api_key"], $settings["secret"], false, true);
$this->fb->user = $facebookUserId;
$this->fb->api_client->session_key = $sessionKey;
$this->fb->api_client->set_user($facebookUserId);
The only other way to get a private users information is if you have an application and that user has given it access. Then you can snatch up any data using a FQL query.
$facebook->api_client->fql_query(
"SELECT first_name, last_name, location
FROM user
WHERE uid={$userid},
AND is_app_user;"
);