Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8683373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:01:33+00:00 2026-06-12T22:01:33+00:00

Issue : The users access token is available from $params[‘access_token’] but $facebook->getUser() returns 0.

  • 0

Issue : The users access token is available from $params['access_token'] but $facebook->getUser() returns 0.

The user is logged in with the

session_start();
$code = $_REQUEST["code"];
if(empty($code)) 
{
    $_SESSION['state'] = md5(uniqid(rand(), TRUE)); // CSRF protection
    $dialog_url = "https://www.facebook.com/dialog/oauth?client_id=" 
    . $app_id . "&redirect_uri=" . urlencode($my_url) . "&state="
    . $_SESSION['state'] . "&scope=";
    echo("<script> top.location.href='" . $dialog_url . "'</script>");
}
if($_SESSION['state'] && ($_SESSION['state'] === $_REQUEST['state'])) 
{
    $token_url = "https://graph.facebook.com/oauth/access_token?"
    . "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)
    . "&client_secret=" . $app_secret . "&code=" . $code;
    $response = file_get_contents($token_url);
    $params = null;
    parse_str($response, $params);
    $_SESSION['access_token'] = $params['access_token'];
    $graph_url = "https://graph.facebook.com/me?access_token=" 
    . $params['access_token'];
    $user = json_decode(file_get_contents($graph_url));
}
else 
{
    echo("Please clear your facebook cookie and re login.  The state id we use to check the authenticity of the session does not match.");
}
$access_token = $params['access_token'];

At this point, the access token is available.

Later in the code, I check if $facebook->getUser() returns the user id. It does not.

    $facebook = new Facebook($config);
    $user_id = $facebook->getUser();

Instead, if I use the $facebook->getLoginUrl(), and let the user click it once (fb detects the user is logged in and does not popup the login box, instead just returns back to app url), $facebook->getUser() does return the id, from then on.

Please let me know if you need more info reg the issue.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:01:35+00:00Added an answer on June 12, 2026 at 10:01 pm

    The function _accessServer opens another request back to your server, sending the access token.

    The function _loginPopup should open the Facebook login popup requesting the appropriate permissions for the user to “allow access” to your application.

    The PHP application should then pass the access token back to the Facebook API

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having problems gaining access to a users photo's from my Facebook app. I request
The Issue: when multiple users have access to the same working directory, permissions issues
Having an interesting issue with redirects. On my user update page (at /username/edit), users
Is there a graph API equivalent of the Facebook Access Token linter/debugger that I
I order to get access to the Facebook API on behalf of a user,
I'm developing a website where the users can access their mailbox from my application.
I found this question , which has an answer, but facebook changed the token
One of my users is having an issue when trying to open an Excel
We have an issue where we need to modify keys for users that are
Happy New Year SO users! I have an issue that I hope someone can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.