突然开始收到400 Bad Request Error

时间:2011-12-17 02:36:10

标签: php facebook facebook-graph-api

几天前,我突然在我的应用中遇到400错误。之前完全没问题。

Warning: file_get_contents(https://graph.facebook.com/me/accounts?access_token=XXXXXXXXXXXX) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request 

真的令人沮丧。我可以让access_token很好,但我不能得到“https://graph.facebook.com/me/accounts?access_token=XXXXXXXXXXXX”。我知道URL是正确的,因为我可以通过在浏览器上加载内容来查看内容。

if(!$code){
     $display = 'page';
     $scope = 'manage_pages';
          $_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection

     $oauth_url = "http://www.facebook.com/dialog/oauth?client_id=" 
            . $app_id . "&redirect_uri=" . urlencode($my_url) . "&state="
            . $_SESSION['state'];

     echo "<script type=\"text/javascript\">\ntop.location.href = \"$oauth_url\";\n</script>";
};

if ($code && $_REQUEST['state'] == $_SESSION['state']){

    $token_url = "https://graph.facebook.com/oauth/access_token?"
       . "client_id=" . $app_id 
       . "&client_secret=" . $app_secret . "&code=" . $code . "&redirect_uri=" . $my_url;

     $response = file_get_contents($token_url);
     $params = null;
     parse_str($response, $params);
     $graph_url = "https://graph.facebook.com/me/accounts?access_token=" . $params['access_token'];

     $user = json_decode(file_get_contents($graph_url));
     $pages_data = $user->data;
}

任何帮助都将非常感谢!

0 个答案:

没有答案