0
我已經成功以這種方式登錄Facebook,但似乎無法讓facebook登錄,只要您點擊Facebook上的任何內容,它就會將您重定向到登錄頁面。我試圖通過curl登錄Facebook,
我考慮了這個+認爲這是因爲curl使用的是cookie而不是瀏覽器,因此當你點擊你的時候沒有通過驗證。
是否有任何設置curl導出到瀏覽器的cookie文件的方法?
我希望我可以簡單地打開PHP文件+它會捲曲登錄我+然後重定向我到我的Facebook頁面,感謝這裏的幫助是代碼:
<?php
// script name: login_to_facebook.php
// coder: Sony AK Knowledge Center - www.sony-ak.com
// your facebook credentials
$username = "xxxxx";
$password = "xxxxx";
// access to facebook home page (to get the cookies)
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://www.facebook.com");
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_ENCODING, "");
curl_setopt($curl, CURLOPT_COOKIEJAR, getcwd() . '/cookies_facebook.cookie');
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)");
$curlData = curl_exec($curl);
curl_close($curl);
// do get some parameters for login to facebook
$charsetTest = substr($curlData, strpos($curlData, "name=\"charset_test\""));
$charsetTest = substr($charsetTest, strpos($charsetTest, "value=") + 7);
$charsetTest = substr($charsetTest, 0, strpos($charsetTest, "\""));
$locale = substr($curlData, strpos($curlData, "name=\"locale\""));
$locale = substr($locale, strpos($locale, "value=") + 7);
$locale = substr($locale, 0, strpos($locale, "\""));
$lsd = substr($curlData, strpos($curlData, "name=\"locale\""));
$lsd = substr($lsd, strpos($lsd, "value=") + 7);
$lsd = substr($lsd, 0, strpos($lsd, "\""));
// do login to facebook
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://login.facebook.com/login.php?login_attempt=1");
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POSTFIELDS, "charset_test=" . $charsetTest . "&locale=" . $locale . "&non_com_login=&email=" . $username . "&pass=" . $password . "&charset_test=" . $charsetTest . "&lsd=" . $lsd);
curl_setopt($curl, CURLOPT_ENCODING, "");
curl_setopt($curl, CURLOPT_COOKIEFILE, getcwd() . '/cookies_facebook.cookie');
curl_setopt($curl, CURLOPT_COOKIEJAR, getcwd() . '/cookies_facebook.cookie');
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)");
$curlData = curl_exec($curl);
curl_close($curl);
echo $curlData;
?>
對這個職位: http://stackoverflow.com/questions/1121280/how-to-let-curl-use-same-cookie-as-the-browser-from-php DAFF說,被送到在HTTP請求標頭中, 我認爲通過將cookies_facebook.cookie +放入一個字符串+然後將其放入該格式。 它可能工作? – 2010-08-06 18:23:57
http://stackoverflow.com/questions/1895955/gmail-facebook-without-username-password-php-login-header-problem 這支持我的情況下,適當使捲曲可能工作? – 2010-08-06 18:25:38
彼得是對的。您提供的第二個鏈接無法工作。它涉及違反安全政策。第一個環節的答案認爲不可能完成任務。 – mattbasta 2010-08-06 18:40:18