对于我的项目目的,我需要远程登录我的Facebook帐户,并从那里检索一些信息。为了登录目的,我使用PHP的cURL库。在执行代码时,Facebook页面要求我在我已启用的浏览器上启用Cookie。代码有问题吗?任何人都可以帮我远程登录到我的账户吗?我是一个新手,如果有任何帮助,我会很感激。 下面是代码远程登录Facebook帐户
<?php
//create array of data to be posted
$post_data['email'] = '*********';
$post_data['password'] = '**********';
$post_data['action'] = 'login';
//traverse array and prepare data for posting
foreach ($post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
//create cURL connection
$ch = curl_init('https://login.facebook.com/login.php?');
//set options
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT,
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//set data to be posted
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
//perform our request
$result = curl_exec($ch);
print_r($result);
//close the connection
curl_close($ch);
?>
什么是问题,为什么你不使用FB API? – Gordon 2010-06-28 06:36:15
感谢您的回答,但我不能使用FB API。 – insightful 2010-06-28 06:52:28