-1

I used the below code to get user's facebook details. Now when I run that, a page comes saying "Please login" where login is an anchor tag. When I click on login, another page comes saying "Invalid App ID: YOUR_APP_ID". When I do all this, i m already logged in to facebook. So why m I not getting details?

<?php
  include 'facebook-php-sdk/src/facebook.php';
  $config = array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET',
'allowSignedRequest' => false // optional but should be set to false for non-canvas 
apps
);

 $facebook = new Facebook($config);
  $user_id = $facebook->getUser();
?>
<html>
  <head></head>
  <body>
  <?php

    if($user_id) {
     // We have a user ID, so probably a logged in user.
      // If not, we'll get an exception, which we handle below.

     try {
      $user_profile = $facebook->api('/me','GET');
      echo "Name: " . $user_profile['name'];

    } catch(FacebookApiException $e) {

       // If the user is logged out, you can have a 
      // user ID even though the access token is invalid.
     // In this case, we'll get an exception, so we'll
    // just ask the user to login again here.

    $login_url = $facebook->getLoginUrl(); 
    echo 'Please <a href="' . $login_url . '">login.</a>';
    error_log($e->getType());
    error_log($e->getMessage());
  }   

} else {

  // No user, print a link for the user to login
  $login_url = $facebook->getLoginUrl();
  echo 'Please <a href="' . $login_url . '">login.</a>';
}
  ?>
 </body>
</html> 
user2828552
  • 67
  • 1
  • 2
  • 10

1 Answers1

2

I think you need to replace YOUR_APP_ID and YOUR_APP_SECRET with the values you find on your Facebook developer page after you created an app.

Where can I find my Facebook application id and secret key?

Read the first question and click on the "here" link.

Community
  • 1
  • 1
hansottowirtz
  • 664
  • 1
  • 6
  • 16
  • now the error comes "Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains." – user2828552 Feb 22 '14 at 07:39
  • What I actually want is to run the code and get as the output the name of the facebook person who is logged in..so please tell me what things to edit in code – user2828552 Feb 22 '14 at 07:52
  • Did you enable sandbox mode on facebook? – hansottowirtz Feb 22 '14 at 09:06