title: Why can't file_get_contents() exchange code for token with Facebook oauth.
body: <p>I cannot exchange code for token using the following code:</p>
  
  <pre><code>extract($_GET);
  $url=urlencode('http://'.DOMAIN.'/admin/');
  $app_id=FB_APPID;
  $fb_token=FB_TOKEN;
  $secret=FB_SECRET;
  
  if(SEND_NEWS_TO_FB){
      if($code=='none'){
              $state=rand(100000000,9999999999999999999);
              $_SESSION['state']=$state;
              $script="
              &lt;script type='text/javascript'&gt;
                      var scope=encodeURI('publish_stream,user_status');
                      var app_id=$app_id;
                      var state=$state;
                      var url=$js_url;
                      window.location.href='https://www.facebook.com/dialog/oauth?                                                                                            client_id='+app_id+'&amp;redirect_uri='+url+'&amp;scope='+scope+'&amp;state='+state;
  
              &lt;/script&gt;";
              echo $script;
      }
  
  
  
  if($code!='none' &amp;&amp; $_SESSION['state']==$state &amp;&amp; $_SESSION['fb_token']!=1){
              $_SESSION['fb_token']=1;
              $token_url="https://graph.facebook.com/oauth/access_token?"
              ."client_id=" .$app_id
              ."&amp;redirect_uri=" .$url
              ."&amp;client_secret=" .$secret
              ."&amp;code=" .$code;
              $response = file_get_contents($token_url);
              $params = null;
              parse_str($response, $params);
              $token=$params['access_token'];
              $qry="UPDATE `settings` SET `FB_token`='$token'";
              $result=mysql_query($qry);
          }
  </code></pre>
  
  <p>Placing the returned $token_url in my browser gives me a page with the token and expiration. Running the script returns a very vague "sorry, there was a problem" message. Almost all of the threads I have seen with problems doing this have been due to differences in the redirect uri's, but both the login and token request get the uri from the exact same place.</p>