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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:04:48+00:00 2026-06-02T10:04:48+00:00

I have a Facebook application where I authorize the user using the PHP SDK.

  • 0

I have a Facebook application where I authorize the user using the PHP SDK. It works most of the time, but sometime it doesn’t and I don’t understand why.

I’m using the code below. First I check if I have a user and if I have a valid token (by requesting “/me”). If so, I exit and show the application. If not, I generate a link with getLoginUrl() and I display that.

When it doesn’t work, the script keeps showing this link. There’s no error message, no information why it’s not working.

I tried printing the $_GET variable and I see that Facebook is appending two query parameters to my URL: “state” and “code”. Does anybody know what they are?

Also any idea why the script below is not working? Is there something I could check to make sure it always works?

$fb_ = new Facebook(array(
    'appId'  => 'appid',
    'secret' => 'secret',
)); 

$userId = $fb_->getUser();
$errorMessage = null;

if ($userId) {
    try {
        $user_ = $fb_->api('/me');
        if (isset($user_['error_code'])) {
            $errorMessage = isset($user_['error_msg']) ? self::$user_['error_msg'] : 'An unknown error occurred';
            $errorMessage .= ' (' . $user_['error_code'] . ')';
            $user_ = null;
        }
    } catch (FacebookApiException $e) {
        $errorMessage = $e->getMessage();
        $user_ = null;
    }
}

if ($user_) return;

$loginUrl = $fb_->getLoginUrl(array(
    'scope' => 'publish_stream,publish_actions'
));

echo '<!doctype html>';
echo '<html xmlns:fb="http://www.facebook.com/2008/fbml">';
echo '<head>';
echo '<title>' . t('Login to Facebook application') . '</title>';
echo '</head>';
echo '<body>';
if ($errorMessage) echo t('Error: %1', $errorMessage) . '<br/>';
echo t('Please login with Facebook first: %1', '<a href="' . $loginUrl . '">' . t('Login with Facebook') . '</a>');
echo '</body>';
echo '</html>';
die();

Edit:

As requested, here is the oauth request:

Request URL:https://www.facebook.com/dialog/oauth?client_id=142896759165492&redirect_uri=http%3A%2F%2Fmxcclient.emarkethink.net%2Flogin&state=ebe253fa859a96e76332935901c32c&scope=publish_stream%2Cpublish_actions
Request Method:GET
Status Code:302 Found

And the response I get from Facebook:

Cache-Control:private, no-cache, no-store, must-revalidate
Content-Length:0
Content-Type:text/html; charset=utf-8
Date:Tue, 17 Apr 2012 07:47:38 GMT
Expires:Sat, 01 Jan 2000 00:00:00 GMT
Location:http://mxcclient.emarkethink.net/login?state=ebe2785a859a96e76332935901c32c&code=AQAN-0ZXg_apegtybid642HOXbU2n5MNl8fYWcPGXiCoFyG7ogJpr53aKBaQKNKz-2wTtPQLpbJd8jAA1fkyw4Kw40Ssylc0b3kFrhnexGJgID8JX-pJEQvKC6wLYL93lQzrA6qFRnS2R6pd0dq-xGLy3YQ-6INC0vQyN_Qhi00M3oAo95b2IeBg4_11E#_=_
P3P:CP="Facebook does not have a P3P policy. Learn why here: http://fb.me/p3p"
Pragma:no-cache
Set-Cookie:locale=en_US; expires=Tue, 24-Apr-2012 07:47:38 GMT; path=/; domain=.facebook.com
X-Cnection:close
X-Content-Type-Options:nosniff
X-FB-Debug:Wnqw6loUBt4vRR21t7Btve/FPWWrfeoXDxhgiHA=
X-XSS-Protection:0
  • 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-02T10:04:49+00:00Added an answer on June 2, 2026 at 10:04 am

    Ok finally found out what the issue was:

    • It didn’t work on Internet Explorer because the application runs in an iframe and no P3 policy was set.

    • It didn’t work on Google Chrome because third-party cookies were blocked (an application running in an iframe is considered “third-party”).

    So in both those cases the login was successful but the authorization token could not be saved, which means the following requests failed.

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

Sidebar

Related Questions

I have an application that integrates with Facebook using Oauth 2. I can authorize
I've developed a Facebook application using the Facebook C# SDK. Interestingly, whenever the user
I have an iFrame Facebook application. I am using the Facebook C# SDK (version
I have a Facebook desktop application and am using the Graph API . I
I have a simple Desktop Facebook application that allows the user to retrieve some
I'm using the Facebook iOS SDK . In my code I have authorized my
I have an issue with SSO using the Facebook SDK for Android. The problem
I have a mobile application that I'm using with Facebook connect. I'm having trouble
I am writing an MVC 3 application and am using Facebook C# SDK .
I am using the official Facebook SDK for Android in my app. I have

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.