Kamis, 20 Januari 2011

curl facebook

<?php
  /*
Copyright (C) 2010 Sony Arianto Kurniawan <sony@sony-ak.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.

---------------------------------------------------------------------

Script Name: post_status_to_facebook.php
Last Update: July 25, 2010
Location of Last Update: Bangalore, India
*/

  // facebook credentials (change to appropriate value)
  $username = "facebook_username";
  $password = "facebook_password";

  // do login to facebook
  $curl = curl_init();
  curl_setopt($curl, CURLOPT_URL, "https://login.facebook.com/login.php?m&next=http://m.facebook.com/home.php");
  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, "email=" . $username . "&pass=" . $password . "&login=Log In");
  curl_setopt($curl, CURLOPT_ENCODING, "");
  curl_setopt($curl, CURLOPT_COOKIEJAR, getcwd() . '/cookies_facebook.cookie');
  $curlData = curl_exec($curl);
  curl_close($curl);

  // do get post url
  $urlPost = substr($curlData, strpos($curlData, "action=\"/a/home") + 8);
  $urlPost = substr($urlPost, 0, strpos($urlPost, "\""));
  $urlPost = "http://m.facebook.com" . $urlPost;

  // do get some parameters for updating the status
  $fbDtsg = substr($curlData, strpos($curlData, "name=\"fb_dtsg\""));
  $fbDtsg = substr($fbDtsg, strpos($fbDtsg, "value=") + 7);
  $fbDtsg = substr($fbDtsg, 0, strpos($fbDtsg, "\""));

  $postFormId = substr($curlData, strpos($curlData, "name=\"post_form_id\""));
  $postFormId = substr($postFormId, strpos($postFormId, "value=") + 7);
  $postFormId = substr($postFormId, 0, strpos($postFormId, "\""));

  // do update facebook status
  $statusMessage = "Hey, I can update my facebook status from PHP (July 25, 2010)";

  $curl = curl_init();
  curl_setopt($curl, CURLOPT_URL, $urlPost);
  curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($curl, CURLOPT_POST, 1);
  curl_setopt($curl, CURLOPT_POSTFIELDS, "fb_dtsg=" . $fbDtsg . "&post_form_id=" . $postFormId . "&status=" . $statusMessage . "&update=Update Status");
  curl_setopt($curl, CURLOPT_ENCODING, "");
  curl_setopt($curl, CURLOPT_COOKIEFILE, getcwd() . '/cookies_facebook.cookie');
  curl_setopt($curl, CURLOPT_COOKIEJAR, getcwd() . '/cookies_facebook.cookie');
  $curlData = curl_exec($curl);
  curl_close($curl);

  // display end facebook page after posting new status message
  echo $curlData;

?>
 <?php
//PHP Curl status update script by http://360percents.com

$status = 'test'; //Must be 420 characters or less!
$email = 'email@domain.com';
$pass = 'p4ssw0rd';

update(urlencode($email),urlencode($pass),urlencode($status));

function update($email, $pass, $status){
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0");
curl_setopt($ch, CURLOPT_URL,"http://m.facebook.com/");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$fbhome = curl_exec ($ch);

preg_match("/<form method=\"post\" action=\"(.*)\">/U", $fbhome, $formaction);
urlencode(preg_match("/<input type=\"hidden\" name=\"charset_test\" value=\"(.*)\" \/>/U", $fbhome, $chartest));
preg_match("/<input type=\"hidden\" name=\"post_form_id\" value=\"(.*)\" \/>/U", $fbhome, $formid);

curl_close ($ch);
unset($ch);

$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0");
curl_setopt($ch, CURLOPT_URL, $formaction[1]);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "post_form_id=".$formid[1]."charset_test=".$chartest[1]."&email=$email&pass=$pass&login=Log+in");

$loggedin = curl_exec ($ch);

preg_match("/<form method=\"post\" id=\"composer_form\" action=\"\/a\/home.php(.*)\">/U", $loggedin, $formaction);
preg_match("/<input type=\"hidden\" name=\"fb_dtsg\" value=\"(.*)\" autocomplete=\"off\" \/>/U", $loggedin, $dtsg);
preg_match("/<input type=\"hidden\" name=\"post_form_id\" value=\"(.*)\" \/>/U", $loggedin, $formid);

curl_close ($ch);
unset($ch);

$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0");
curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/a/home.php'.$formaction[1]);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "charset_test=".$chartest[1]."&fb_dtsg=".$dtsg[1]."&post_form_id=".$formid[1]."&status=$status&update=Share");

$buf2 = curl_exec ($ch);

curl_close ($ch);
unset($ch);
return 0;
}
?>

1 komentar:

  1. om mau nanya ini dapet nya dari mana,,
    maav masih newbie

    /cookies_facebook.cookie

    klo bisa bles via e mail ya om,,
    mohon bantuan nya,,makasih

    BalasHapus