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 6336351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:02:24+00:00 2026-05-24T19:02:24+00:00

I’m new to developing with the Facebook API, so thank you in advance for

  • 0

I’m new to developing with the Facebook API, so thank you in advance for your patience in helping me resolve my problem.

I’m using the Facebook PHP SDK 3 that checks for the state token and user token code to verify authentication, but it seems like it only works when I hit the app through Facebook.


Step by step in more detail:

(1) Delete Application Permissions > To start fresh and try to troubleshoot I login to Facebook and delete my user access for the application so that I will get prompted to accept the permissions again.

(2) Refresh Web App > Then I refresh my application and it doesn’t know that I have a Facebook session!

Shouldn’t the application be able to at least see my Facebook user id when I’m logged in to Facebook?

Did deleting the application from my user cause the application to lose all access?

(3) Logout of Facebook, Refresh App > Since this doesn’t work I log out of Facebook and refresh my web app to start over.

Generate the Facebook Login or Logout link based on $user information

public function run(){

  $FB = &$this->getFacebook();
  $user = $FB->getUser();

  $user_dat = $FB->api('/me');
  $logoutUrl = $FB->getLoginUrl(array('scope'=> $fbPermissions,'redirect_uri'=> $appBaseURL)); 
  $loginUrl = $FB->getLogoutUrl();

    ?>
    <h1>php-sdk</h1>

    <?php if ($user): ?>
      <a href="<?php echo $logoutUrl; ?>">Logout</a>
    <?php else: ?>
      <div>
        Login using OAuth 2.0 handled by the PHP SDK:
        <a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
      </div>
    <?php endif ?>
    <?php if ($user): ?>
      <h3>You</h3>
      <img src="https://graph.facebook.com/<?php echo $user; ?>/picture">
      <h3>Your User Object (/me)</h3>
      <pre><?php print_r($user_dat); ?></pre>
    <?php else: ?>
      <strong><em>You are not Connected.</em></strong>
    <?php endif ?>
<?php   } ?>

(4) Click Generated Login Link > The FB login link is generated on my web application (outside of Facebook) I click it and redirects me to Facebook to login.

Generated Login URL

https://www.facebook.com/login.php?
api_key=112233445566778
&skip_api_login=1
&display=page&
cancel_url=http://www.mywebapp.com/app/beta/?error_reason=user_denied&error=access_denied
&error_description=The+user+denied+your+request.
&state=99ff88cc33dd77aa11bb00cc2266dd11
&fbconnect=1
&next=https://www.facebook.com/connect/uiserver.php?method=permissions.request
&app_id=112233445566778
&display=page
&redirect_uri=http://www.mywebapp.com/app/beta/?response_type=code&state=99ff88cc33dd77aa11bb00cc2266dd11
&fbconnect=1
&perms=user_about_me,user_activities,user_likes,email,user_online_presence,read_friendlists,manage_notifications,publish_stream
&from_login=1
&rcount=1

(5) Login to Facebook, Allow App Permissions > I Login and then it then asks me to allow permissions to my application, which I do by clicking ‘Allow’ and Facebook redirects me back to my application with this URL.

http://www.mywebapp.com/app/beta/?
code=ABCxxx
&state=b3f5efffc496b3f5efff38e32604e3

However when I get back to the application my server error logs spit up an error message:

[error] ***CSRF state token does not match one provided.***

And the application thinks that I’m still not logged in, and doesn’t display any user information!

It looks like the application’s state token does not match the one returned from Facebook after the user accepts the applications permissions via Ouath.

In this case the state token I sent over as part of the login link was:

state=9655d77aa198fc0a29774694134dd0c7

but then facebook redirected me back to my application with this state token!

state=b3f5efffa4169f3c4b816838e32604f5

The token I sent over actually looks like the token from the previous session, so I was thinking maybe I need to clear the session information before logging in again. This doesn’t seem to happen within the Facebook SDK, so do I need to implement this myself?

(6) Refresh Web App in Facebook > Then to just make sure I’m not crazy I go to Facebook and see that I am logged in, and then I hit the web app through facebook

http://apps.facebook.com/mywebapp/

and what do you know, my application is showing all of my user info, user access token and everything from within Facebook, however =/

(7) Refresh Standalone App > I then go back to my webapp — refresh it — and now it has all the info as well!

What is wrong that I cannot login through my application using the PHP SDK?

Why can’t my application see a Facebook User id when they’re not on the app?

  • 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-05-24T19:02:25+00:00Added an answer on May 24, 2026 at 7:02 pm

    This is really dumb, but basically the API was broken. Facebook recently fixed it so now I’m no longer having these issues! =/

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the

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.