0

Following this discussion i can't figure it out how to getUserId from session or how to create session from a signed request in new SDK 4 for PHP? I'm trying to migrate my apps from old SDK to new one and my code doesn't work well. I'm trying to get the user ID on page tab where i'm an admin. I've tried to getSession from FacebookPageTabHelper with no luck.

My php code:

session_start();
require_once '../api/facebook/autoload.php';

use Facebook\FacebookSession;
use Facebook\FacebookPageTabHelper;

FacebookSession::setDefaultApplication(APP_ID, APP_SECRET);
$pageHelper = new FacebookPageTabHelper();

$page = $pageHelper->getPageId();
$admin = $pageHelper->isAdmin();
$fan = $pageHelper->isLiked();
$appdata = $pageHelper->getSignedRequest()->payload['app_data'];
$session = $pageHelper->getSession();
$user = $session->getUserId(); // always empty

1 Answer 1

3

Facebook API doesn't provide you with this information anymore (if you use the user access token). You should get the ID of the user by looking at his posts or his comments, and even by this way you need to guess that he is a public user otherwise it will not work.

If you can login with the app token it should work but it's not easy to get confirmation for your application by Facebook.

Sign up to request clarification or add additional context in comments.

2 Comments

I'm asking about user ID for page/app admin. That means user (page admin who actually install the app) have provided basic permissions already.
Well then it should work. maybe try to check your token permissions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.