In FB SDK 3.0, you could run $facebook->getUser()
to get the user's Facebook UID.
SDK 4.0 doesn't have a BaseFacebook object any more; I can't see how to get the user ID off of a FacebookSession created by FacebookJavaScriptLoginHelper. How do you do it?
If you already have an active session or an access token, you can do the following to get the user_id:
// set session from cookie or via helper
$session = new FacebookSession( $session->getToken() );
$user_id = $session->getSessionInfo()->asArray()['user_id']
echo $user_id
See this tutorial for information on using a session saved in a cookie or creating a new session. It's a long solution but this the easiest way to retrieve the user_id using the new SDK. It's advisable to save it in a session for easier retrieval.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With