tags:

views:

29

answers:

2

Hello I am developing a SMS application for updating facebook status in PHP. I can collect username and password of user. I know it can be done by Status.set ,but how can I use the username and password and get the necessary session key and as such. Please help.

A: 

You'll have to use extended permissions (offline_access). The user will still have to authenticate with oauth, the most 'inobtrusive' way would be the Desktop Application route

Wrikken
hey but it says "Facebook's OAuth implementation does not include explicit desktop application support. However, if your desktop application can embed a Web browser, you can add Facebook support to your application easily using the same OAuth User-Agent Flow used by JavaScript clients."
Ashwin
+1  A: 

Hope this will help someone

function setFacebookStatus($status, $login_email, $login_pass, $debug=false) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://login.facebook.com/login.php?m&next=http%3A%2F%2Fm.facebook.com%2Fhome.php');
curl_setopt($ch, CURLOPT_POSTFIELDS, 'email=' . urlencode($login_email) . '&pass=' . urlencode($login_pass) . '&login=' . urlencode("Log in"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.12) Gecko/2009070611 Firefox/3.0.12");
curl_exec($ch);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/home.php');
$page = curl_exec($ch);
curl_setopt($ch, CURLOPT_POST, 1);
preg_match("/input type=\"hidden\" name=\"post_form_id\" value=\"(.*?)\"/", $page, $form_id);
preg_match("/input type=\"hidden\" name=\"fb_dtsg\" value=\"(.*?)\"/", $page, $fb_dtsg);
preg_match("/input type=\"hidden\" name=\"charset_test\" value=\"(.*?)\"/", $page, $charset_test);
preg_match("/input type=\"submit\" class=\"button\" name=\"update\" value=\"(.*?)\"/", $page, $update);
preg_match_all("#<form([^>]*)>(.*)</form>#Ui", $page, $form_ar);
for($i=0;$i<count($form_ar[0]);$i++) {
if(stristr($form_ar[0][$i],"post_form_id")) preg_match("/form action=\"(.*?)\"/", $page, $form_num);    
}
$strpost = 'post_form_id=' . $form_id[1] . '&status=' . urlencode($status) . '&update=' . urlencode($update[1]) . '&charset_test=' . urlencode($charset_test[1]) . '&fb_dtsg=' . urlencode($fb_dtsg[1]);
if($debug) {
    echo "Parameters sent: ".$strpost."<hr>";
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $strpost );
curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com' . $form_num[1]);
curl_exec($ch);
if ($debug) {
    print_r(curl_getinfo($ch));
    echo curl_errno($ch) . '-' . curl_error($ch);
    echo "<br><br>Your Facebook status seems to have been updated.";
}
curl_close($ch); }
Ashwin