Pogledajte određenu poruku
Staro 26. 06. 2011.   #1
webarto
expert
Grand Master
 
Avatar webarto
 
Datum učlanjenja: 11.04.2010
Poruke: 998
Hvala: 141
959 "Hvala" u 153 poruka
webarto is on a distinguished roadwebarto is on a distinguished roadwebarto is on a distinguished roadwebarto is on a distinguished roadwebarto is on a distinguished roadwebarto is on a distinguished roadwebarto is on a distinguished roadwebarto is on a distinguished road
Default Facebook Profiler

Yet another useless crappy code
Uglavnom klijent je na Facebooku napravio profile za svoju firmu a ne page. Pošto ovo ne može da se odradi preko API bez tokena, urađen je klasični scrapping javnog profila (ovo funkcioniše samo ako su "prijatelji" vidljivi).



PHP kôd:
class Profiler{
    
    public function 
display($id){

        
$api $this->curl("https://graph.facebook.com/$id");
        
$api json_decode($apitrue);
        
        
$url $api["link"];
        
$html $this->curl($url);
        
$html preg_replace("#(\\\u[a-fA-F0-9]{4})#e""chr(hexdec('\\1'))"$html);
        
$html stripslashes($html);

        
preg_match_all('#tabindex="-1"><img class="img" src="http://profile.ak.fbcdn.net/(.*?)" alt="(.*?)" />#is'$html$matches);
        unset(
$matches[0]);

        
$count count($matches[1]);
        for(
$i 0$i $count$i++){
            
$img .= '<div><img alt="" width="50px" height="50px" src="http://profile.ak.fbcdn.net/'.$matches[1][$i].'"/><p>'.$matches[2][$i].'</p></div>';   
        }
        
        return 
'
        <div id="facebook">
        <h1 class="profile"><img alt="" src="https://graph.facebook.com/'
.$id.'/picture"/> <a href="'.$api["link"].'" target="_blank">'.$api["name"].' @ Facebook</a></h1>
        <div class="friends">'
.$img.'</div>
        </div>'
;
    
    }

    private function 
curl($url$nobody false){
        
$ch curl_init();
        
curl_setopt($chCURLOPT_URL$url);
        
curl_setopt($chCURLOPT_USERAGENT"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
        
curl_setopt($chCURLOPT_FOLLOWLOCATION1);
        
curl_setopt($chCURLOPT_ENCODING"gzip");
        
curl_setopt($chCURLOPT_RETURNTRANSFER1);
        if(
$nobody == true){
            
curl_setopt($chCURLOPT_HEADER1);
            
curl_setopt($chCURLOPT_NOBODY1);
        }
        
$data curl_exec($ch);
        
curl_close($ch);
        return 
$data;
    }
    

PHP kôd:
$fb = new Profiler;
echo 
$fb->display("100000414144463"); 
Ovdje možete vidjeti učitavanje preko AJAX... http://cacfolija.ba/
__________________
Github // LinkedIn // PHP // ZCE // Stackoverflow PHP // Site5 Web Hosting
webarto je offline   Odgovorite uz citat