title: Facebook PHP SDK - How to get access token?
body: <p>I'm trying to post on user's Facebook wall from my app. The user granted the permissions to the app to post on his wall, and I have userid in db. I need to send the post automatically, without the user logging in again.</p>
  
  <p>My code is:</p>
  
  <pre><code>try{
      require_once(dirname(__FILE__) . '\lib\facebook-php\src\facebook.php' );
  }
  catch(Exception $o){
          print_r($o);
  }
  $config = array(
      'appId' =&gt; '123456',
      'secret' =&gt; '454544',
      'allowSignedRequest' =&gt; false // optional but should be set to false for non-canvas apps
  );
  
  $facebook = new Facebook($config);
  $user_id = $facebook-&gt;getUser();
  $user_id = '123456';
  
  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 {
  
          $ret_obj = $facebook-&gt;api('/me/feed', 'POST',
              array(
                  'access_token' =&gt; $facebook-&gt;getAccessToken(),
                  'link' =&gt; 'www.example.com',
                  'message' =&gt; 'Posting with the PHP SDK!'
              ));
          echo '&lt;pre&gt;Post ID: ' . $ret_obj['id'] . '&lt;/pre&gt;';
  
          // Give the user a logout link
          echo '&lt;br /&gt;&lt;a href="' . $facebook-&gt;getLogoutUrl() . '"&gt;logout&lt;/a&gt;';
      } 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.
          var_dump($e);
          $login_url = $facebook-&gt;getLoginUrl( array(
              'scope' =&gt; 'publish_stream'
          ));
          echo 'Please &lt;a href="' . $login_url . '"&gt;login.&lt;/a&gt;';
          error_log($e-&gt;getType());
          error_log($e-&gt;getMessage());
      }
  } else {
  
      // No user, so print a link for the user to login
      // To post to a user's wall, we need publish_stream permission
      // We'll use the current URL as the redirect_uri, so we don't
      // need to specify it here.
      $login_url = $facebook-&gt;getLoginUrl( array( 'scope' =&gt; 'publish_stream' ) );
      echo 'Please &lt;a href="' . $login_url . '"&gt;login.&lt;/a&gt;';
  
  }
  </code></pre>
  
  <p>This throws <code>An active access token must be used to query information about the current user.</code> error and asks for login. After I click login, the post is sucesfully posted. </p>
  
  <p>How can I get the access token with userid without the user logging in?</p>