使用cURL进行Facebook身份验证(php)

时间:2010-10-06 00:42:33

标签: php facebook curl

尝试使用cURL进行facebook身份验证,这就是我所拥有的:

        $url = "https://graph.facebook.com/oauth/access_token";
        $postString = "?client_id=$client_id&redirect_uri=$redirect_uri&client_secret=$client_secret&code=$code";
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_FAILONERROR, 1);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
        //curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $postString);
        $response = curl_exec($curl);

但每次只返回false。

我对使用cURL很新,所以我可能会犯一些初学者的错误,但我很困惑为什么这根本不起作用。

非常感谢任何帮助!

2 个答案:

答案 0 :(得分:0)

这可能太明显了,可能是一个错字,但是:

//curl_setopt($curl, CURLOPT_POST, 1);

应该取消注释。

答案 1 :(得分:0)

删除“?”从你的帖子字符串的开头..应该修复它!