title: facebook extending the access token
body: <p>Hi I've seen the answer here 
  <a href="http://facebook.stackoverflow.com/questions/8982025/how-to-extend-access-token-validity-since-offline-access-deprecation">http://facebook.stackoverflow.com/questions/8982025/how-to-extend-access-token-validity-since-offline-access-deprecation</a>
  and gave it a go but I'm having trouble getting it to work.</p>
  
  <p>I have an expired token - but obviosuly just need a way to auto update it.
  is this possible can someone slip me some code</p>
  
  <p>At present I'm trying this</p>
  
  <pre><code>try {
  $result = $facebook-&gt;api(
                  '/me/permissions/',
                  'get',
                  array('access_token' =&gt; $token)
          );
  }
  catch(FacebookApiException $e) {
  
      echo "token invalid";
      $facebook-&gt;setAccessToken($token);
      echo $facebook-&gt;getExtendedAccessToken();
  }
  </code></pre>
  
  <p>But I still get</p>
  
  <pre><code>token invalid{"error":{"message":"Error validating access token: Session has expired at unix time 1338858000. The current unix time is 1338985046.","type":"OAuthException","code":190,"error_subcode":463}}
  </code></pre>
  
  <p>Any help. Thanks
  Richard</p>
  
  <hr>
  
  <p>Hi thanks for your help I've got the extended stuff to work and I'm understanding a little more
  - I have a followup question say my token becomes invalid - what to do then?
  I'm still logged into facebook and I've given permission to my app so it's all there I just need a new key.</p>
  
  <p>I've tried this</p>
  
  <pre><code>$facebook = new Facebook(array(
                  'appId'  =&gt; FACEBOOKAPPID,
                  'secret' =&gt; FACEBOOKSECRET,
                  'cookie' =&gt; true,
              ));
  
  $url = $facebook-&gt;getLoginUrl(array('canvas'=&gt;1,'fbconnent'=&gt;1,'scope'=&gt;'offline_access,publish_stream,email,user_about_me,user_birthday,user_website'));
  file_get_contents($url);
  $fb_session = $facebook-&gt;getUser();
  echo $fb_session.'&lt;br /&gt;';
  
  $token = $facebook-&gt;getExtendedAccessToken();           
  echo $token.'&lt;br /&gt;';
  </code></pre>
  
  <p>As it seems that you need to 'login' to facebook to get the details again but it seems that you can't use file_get_contents as facebook requires the cookie that is on your machine. I'm trying to do this on the fly so not to bother the user with any popups and also they have already given the app permission.</p>
  
  <p>Any ideas?
  Richard</p>
  
  <p>Oh and just doing this doesn't seem to work either.</p>
  
  <pre><code>$facebook = new Facebook(array(
      'appId'  =&gt; $this-&gt;fbApiKey,
      'secret' =&gt; $this-&gt;fbSecretKey,
      'cookie' =&gt; true,
  ));
  $token = $facebook-&gt;getAccessToken();
  </code></pre>