用于登录 Facebook 的 PHP cURL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23186168/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP cURL to login to facebook
提问by Stumblinbear
I am attempting to login to Facebook using curl, but everything I have tried has ended up in Facebook saying, "Cookies are not enabled on your browser. Please enable cookies in your browser preferences to continue."
我正在尝试使用 curl 登录 Facebook,但我尝试的所有内容都在 Facebook 中结束,提示“您的浏览器未启用 Cookie。请在您的浏览器首选项中启用 Cookie 以继续”。
$login_email = 'email';
$login_pass = 'password';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.facebook.com/login.php');
curl_setopt($ch, CURLOPT_POSTFIELDS,'email='.urlencode($login_email).'&pass='.urlencode($login_pass).'&login=Login');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
curl_setopt($ch, CURLOPT_REFERER, "http://www.facebook.com");
$page = curl_exec($ch) or die(curl_error($ch));
echo $page;
The cookie file 'cookies.txt' exists, and has 644 permissions. I have also attempted to use multiple of the snippets online, but they all give the same error. I cannot continue with my current project until I get this working and I am able to navigate Facebook using curl as well. Any help is appreciated.
cookie 文件 'cookies.txt' 存在,并且具有 644 权限。我还尝试在线使用多个片段,但它们都给出了相同的错误。在我开始工作之前,我无法继续我当前的项目,并且我也可以使用 curl 浏览 Facebook。任何帮助表示赞赏。
Thanks in advance.
提前致谢。
采纳答案by CONvid19
This may help:
这可能有帮助:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
Check this answer:
检查这个答案:
回答by Zen
I had the same problem and I fixed it by adding the following:
我遇到了同样的问题,我通过添加以下内容修复了它:
curl_setopt($s, CURLOPT_COOKIESESSION, false);
curl_setopt($s, CURLOPT_COOKIESESSION, false);
回答by Bruno Andrade
This must be used on curl cookie :
这必须用于 curl cookie :
curl_setopt($ch, CURLOPT_COOKIEFILE, getcwd () . '/mirazmac_cookie.txt' );
curl_setopt($ch, CURLOPT_COOKIEJAR, getcwd () . '/mirazmac_cookie.txt' );
回答by Wit Wikky
Better to use use facebook login sdk
最好使用使用facebook登录sdk
Because Facebook constantly makes changes to their source code.
因为 Facebook 不断地更改他们的源代码。

