Advertisement
greg1996

Facebook message downloader

Feb 10th, 2013
4,878
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.66 KB | None | 0 0
  1. <?php
  2.         // CODED BY Metts  / metts.blog.hu / da.metts@hotmail.com
  3.         // FACEBOOK all message download
  4.         // A Kódért felelősséget nem vállalok!
  5.         // kő még simple_html_dom.php http://simplehtmldom.sourceforge.net/ egy mappaba vele
  6.         // elvileg letölti az összes üzenet amit eddig a felhasználóval beszéltünk
  7. /*
  8. completed by Greg
  9. mosmá' működik is
  10.  
  11. tessék böngészőbő' indítani
  12. üzeneteket ide rakja: c://xampp/htdocs/out.html
  13. */
  14.  
  15. $login_email = '';
  16. $login_pass = '';
  17.  
  18. header('Content-Type: text/html; charset=utf-8');
  19. include("phpdom/simple_html_dom.php");
  20.  
  21. set_time_limit(0);
  22.  
  23. function req (&$ch) {
  24.     curl_setopt($ch, CURLOPT_HEADER, 0);
  25.     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  26.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  27.     curl_setopt($ch, CURLOPT_COOKIEJAR, str_replace('\\','/',dirname(__FILE__)).'/fb_cookies.txt');
  28.     curl_setopt($ch, CURLOPT_COOKIEFILE, str_replace('\\','/',dirname(__FILE__)).'/fb_cookies.txt');
  29.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  30.     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");
  31.     curl_setopt($ch, CURLOPT_NOBODY, false);
  32.     return curl_exec($ch);
  33. }
  34.  
  35. function fb_login($login_email, $login_pass) {
  36.     $ch = curl_init();
  37.     curl_setopt($ch, CURLOPT_URL, 'http://login.facebook.com/login.php?login_attempt=1');
  38.     curl_setopt($ch, CURLOPT_POSTFIELDS,'charset_test=%E2%82%AC%2C%C2%B4%2C%E2%82%AC%2C%C2%B4%2C%E6%B0%B4%2C%D0%94%2C%D0%84&locale=en_US&email='.urlencode($login_email).'&pass='.urlencode($login_pass).'&pass_placeholder=&charset_test=%E2%82%AC%2C%C2%B4%2C%E2%82%AC%2C%C2%B4%2C%E6%B0%B4%2C%D0%94%2C%D0%84');
  39.     curl_setopt($ch, CURLOPT_POST, 1);
  40.     $content = req ($ch);
  41.    
  42.     $err = curl_error($ch);
  43.     if ($err == 0) {
  44.         $html = str_get_html($content);
  45.         $ret = $html->find('.login_error_box');
  46.         if (count($ret) != 0) {
  47.             $ret = $ret[0];
  48.             return $ret->innertext;
  49.         } else {
  50.             return true;
  51.         }
  52.     } else {
  53.         curl_close($ch);
  54.         return $err;
  55.     }
  56. }
  57.  
  58. function getUsers () {
  59.     $ch = curl_init();
  60.     curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/messages/');
  61.     $content = req ($ch);
  62.     $html = str_get_html($content);
  63.     return $html->find('#threadlist_rows', 0);
  64. }
  65.  
  66. function get_messages ($id) {
  67.     $myFile = "c://xampp/htdocs/out.html";
  68.     $fh = fopen($myFile, 'w');
  69.     $last = '';
  70.     for ($i = 0; true; $i += 7) {
  71.         $url = 'http://m.facebook.com/messages/read/?deleteselected=0&forward=0&start=' . $i . '&page_size=0&tids=' . $id . '&sk=inbox&tid=' . $id . '&see_newer=1&refid=12';
  72.        
  73.         for ($j = 0; $j < 5; $j ++) {
  74.             $ch = curl_init();
  75.             curl_setopt($ch, CURLOPT_URL, $url);
  76.             curl_setopt($ch, CURLOPT_ENCODING, "");
  77.             $html = str_get_html(req ($ch));
  78.            
  79.             if (is_object ($html)) {
  80.                 break;
  81.             } else {
  82.                 echo "Error @ try #$j $html\n";
  83.             }
  84.             flush();
  85.             ob_flush();
  86.         }
  87.        
  88.         $ret = $html->find('div[class=acw apl abt]');
  89.         foreach($ret as $r) {
  90.             fwrite($fh, $r);
  91.             fwrite($fh, "----------\n");
  92.         }
  93.        
  94.         echo "got $i<br/>";
  95.         flush();
  96.         ob_flush();
  97.        
  98.         if ($r == $last) {
  99.             break;
  100.         } else {
  101.             $last = $r;
  102.         }
  103.     }
  104.     fclose($fh);
  105. }
  106.  
  107.  
  108.  
  109. if (isset ($_GET['u'])) {
  110.     get_messages ($_GET['u']);
  111. } else {
  112.     for ($i = 0; ($i < 3 && ($ret = fb_login($login_email, $login_pass)) !== true); $i ++);
  113.     if ($ret !== true) {
  114.         exit ("<b>Belépési hiba!</b><br/>$ret");
  115.     }
  116.    
  117.     $users = getUsers ()->find('a');
  118.     for ($i = 0; $i < count ($users); $i ++) {
  119.         parse_str(parse_url($users[$i]->href, PHP_URL_QUERY), $query);
  120.         if (isset($query['tid'])) {
  121.             echo '<a href="?u=' . $query['tid'] . '">' . trim($users[$i]->plaintext) . '</a><br/>';
  122.         }
  123.     }
  124. }
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement