简体   繁体   English

PHP cURL登录facebook

[英]PHP cURL to login to facebook

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. cookie文件'cookies.txt'存在,并具有644权限。 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. 在我开始工作之前,我无法继续我当前的项目,并且我也能够使用curl导航Facebook。 Any help is appreciated. 任何帮助表示赞赏。

Thanks in advance. 提前致谢。

This may help: 这可能有所帮助:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

Check this answer: 检查这个答案:

Post to a Facebook user's wall with cURL PHP 使用cURL PHP发布到Facebook用户的墙上

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);

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' );

Better to use use facebook login sdk 最好使用facebook登录sdk

Because Facebook constantly makes changes to their source code. 因为Facebook不断对其源代码进行更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM