350D
350D

Reputation: 11449

Get user ID using Facebook PHP SDK 4

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

Upvotes: 0

Views: 667

Answers (1)

user3100708
user3100708

Reputation: 148

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.

Upvotes: 3

Related Questions