title: Facebook php sdk - how to auto-login my app on website
body: <p>i'd like to don't show the login button on my webpage and make it automatic so if somebody visit my site it shows him the content from facebook directly without clicking on the login button every time.  Can you help me?</p>
  
  <p>I'm using Facebook PHP SDK4 APIs.</p>
  
  <p>Following is my code:</p>
  
  <pre><code>&lt;?php
  
  // Must pass session data for the library to work (only if not already included in your app)
  session_start();
  
  // Autoload the required files
  require_once('phpsdk4/autoload.php');
  
  use Facebook\FacebookSession;
  use Facebook\FacebookRedirectLoginHelper;
  use Facebook\FacebookRequest;
  use Facebook\FacebookResponse;
  use Facebook\FacebookSDKException;
  use Facebook\FacebookRequestException;
  use Facebook\FacebookAuthorizationException;
  use Facebook\GraphObject;
  use Facebook\GraphUser;
  use Facebook\Entities\AccessToken;
  use Facebook\HttpClients\FacebookCurl;
  use Facebook\HttpClients\FacebookCurlHttpClient;
  use Facebook\HttpClients\FacebookHttpable;
  
  // Facebook app settings
  $app_id = '123456';
  $app_secret = 'appsecretpassword';
  $redirect_uri = 'mywebpageaddress';
  
  // Initialize the SDK
  FacebookSession::setDefaultApplication( $app_id, $app_secret );
  
  ?&gt;
  
  &lt;!DOCTYPE html&gt;
  &lt;html lang="it"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html" charset="utf-8" /&gt;
  &lt;title&gt;Facebook SDK test&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;?php
  
  $helper = new FacebookRedirectLoginHelper($redirect_uri, $app_id, $app_secret);
  try {
      $session = $helper-&gt;getSessionFromRedirect();
  }
  catch(FacebookRequestException $ex) { } 
  catch(\Exception $ex) { }
  
  $loggedIn = false;
  
  if (isset($session))
  {
      if ($session) 
      {
          $loggedIn = true;
          try 
          {
              // Logged in
              $user_photos = (new FacebookRequest($session, 'GET', '/me/statuses'))-&gt;execute()-&gt;getGraphObject(GraphUser::className());
              $user_photos = $user_photos-&gt;asArray();
  
              echo "&lt;pre&gt;";
              print_r($user_photos);
              echo "&lt;/pre&gt;";
          } 
          catch(FacebookRequestException $e) 
          { 
              echo "Exception occured, code: " . $e-&gt;getCode();
              echo " with message: " . $e-&gt;getMessage();  
          }           
      }
  }
  if (!$loggedIn)
  {
    //$loginUrl = $helper-&gt;getLoginUrl();
    $loginUrl = $helper-&gt;getLoginUrl(array('user_status'));
    echo '&lt;a href="' . $loginUrl . '"&gt;Login&lt;/a&gt;';
  }
  
  ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>