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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:58:28+00:00 2026-05-26T10:58:28+00:00

I am trying to migrate to the new Facebook API for websites, and just

  • 0

I am trying to migrate to the new Facebook API for websites, and just can’t get it to work smoothly. I would like to use the Javascript and PHP SDKs together, but am having problems. I can authenticate, but the page doesn’t refresh automatically.

I have searched throughout SO and the Facebook documentation, but still can’t get this to work correctly. I have read through http://developers.facebook.com/blog/post/534/, dowloaded the latest PHP SDK (3.1.1), and basically copied the example on the aforementioned post from facebook. I have made what I think are the correct settings in my app ‘Migration’ settings, but this could be where the problem lies. I can’t post an image, so here are the setting:

  • Remove Deprecated API’s: Enabled
  • Forces use of login secret: Enabled
  • Encrypted Access token: Enabled
  • Enhanced Auth Dialog: Enabled
  • (Everything else is disabled)

Here is the code:

<?php

require 'php-sdk/src/facebook.php';

$facebook = new Facebook(array(
  'appId'  => 'YOUR_APP_ID',
  'secret' => 'YOUR_APP_SECRET',
));

// See if there is a user from a cookie
$user = $facebook->getUser();

if ($user) {
  try {
  // Proceed knowing you have a logged in user who's authenticated.
  $user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
  echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
  $user = null;
  }
}

?>
<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
  <body>
    <?php if ($user_profile) { ?>
      Your user profile is 
      <pre>            
         <?php print htmlspecialchars(print_r($user_profile, true)) ?>
      </pre> 
    <?php } else { ?>
      <fb:login-button></fb:login-button>
    <?php } ?>
    <div id="fb-root"></div>
    <script>               
      window.fbAsyncInit = function() {
         FB.init({
           appId: '<?php echo $facebook->getAppID() ?>', 
           cookie: true, 
           xfbml: true,
           oauth: true
         });
        FB.Event.subscribe('auth.login', function(response) {
          window.location.reload();
        });
        FB.Event.subscribe('auth.logout', function(response) {
          window.location.reload();
        });
       };
      (function() {
        var e = document.createElement('script'); e.async = true;
        e.src = document.location.protocol +
          '//connect.facebook.net/en_US/all.js';
          document.getElementById('fb-root').appendChild(e);
      }());
    </script>
  </body>
</html>
  • 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-26T10:58:29+00:00Added an answer on May 26, 2026 at 10:58 am

    I was going to write this as a comment but it got a bit long… 🙂

    A couple of pointers using the PHP SDK:

    $facebook->getUser(); 
    

    This will work regardless of authentication. getUser() pulls publicly available data that does not require an access token, HOWEVER if you do have an access token and the user has provided email permissions for example, this method will also contain their email address.

    A better test for an authenticated user:

    $code = $_REQUEST['code'] ? true : false;
    if (!$code) {
        echo ("<script>window.top.location=\"...\"</script>");
    }
    

    will check if a user has authorised your app.

    $access = $facebook->getAccessToken();
    

    Make sure that you always request the Access Token (priority!) You will only ever recieve a signed request when you have been redirected from a facebook dialogue to your app. (i.e.) oAUTH dialogue. This method of the SDK will also save your Access Token to a session variable. You can call the getAccessToken() method on any subsequent app page where a PHP session is active EVEN WHEN no signed request has been issued.

    Now that you have your valid access token for the logged in user, you can proceed with:

    $user = $facebook->api('/me');
    

    or, simpler still:

    $user = $facebook->getUser();
    

    I tend to reserve API calls for more complex requests such as posting to a users feed / friends feed.

    So to recap:

    -> check for $code
    -> get signed request on first page after oAuth dialogue.
    -> If browser cookies are disabled (likely in ie) don’t forget to pass your session to the next page with the SID constant. If you don’t, you will loose your stored access token (not good!).

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

Sidebar

Related Questions

I've been trying to migrate my project to new API, but I get the
I am trying to migrate lots of websites to a new host which does
I'm trying to migrate from C2DM to GCM, and it mostly works just fine.
I'm new to Postgresql and I'm trying to migrate my application from MySQL. I
I was unsuccessful trying to migrate a bbPress 1.0 instalation to the new bbPress
I am somewhat new to spring security and I am trying to migrate an
I am trying to migrate over to Python from Matlab and can't figure out
I have inherited a webserver already serving some websites. I am trying to migrate
Trying to migrate from an old database to a new one in which the
I'm trying to migrate an old asp.net 1.1 application to target the new .net

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.