Advertisement
tpaper

Pic url grabber

Nov 23rd, 2016
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.19 KB | None | 0 0
  1. <?php
  2.  
  3. //Salva in un file tutti gli url appartenenti ad un gruppo.
  4. //Script scritto in fretta e furia, non ottimizzato, alla cazzo. Funziona per miracolo. Insomma: nessuna garanzia.
  5. //Una sola cosa: se lo usate per creare "opere pubbliche", almeno citatemi.
  6. //Enrico Ronconi <enrico.ronconi.p@gmail.com> - 23 Nov 2016
  7.  
  8. $context = stream_context_create(array('http' => array('header'=>'Connection: close\r\n')));
  9.  
  10. function add_ids($ids_array,$data){
  11.     foreach ($data as $user) {
  12.         array_push($ids_array, [$user["name"],$user["id"]]);
  13.     }
  14.     return $ids_array;
  15. }
  16. $at="access token here";
  17. $resp = file_get_contents("https://graph.facebook.com/v2.8/831654706902078/members?limit=750&access_token=$at",false,$context);
  18.  
  19. $resp = json_decode($resp,true);
  20. $ids = add_ids(array(),$resp["data"]);
  21. $limit = false;
  22. while(array_key_exists("next",$resp["paging"])){
  23.     $resp = file_get_contents($resp["paging"]["next"],false,$context);
  24.     $resp = json_decode($resp,true);
  25.     $ids = add_ids($ids,$resp["data"]);
  26.     echo("Raccolti: ".(string)count($ids)."\n");
  27.     //var_dump($resp["paging"]);
  28.     usleep(1000*250);
  29.     if($limit){
  30.         if(count($ids)>=$limit) break;
  31.     }
  32. }
  33.  
  34. $only_id = array();
  35.    
  36. foreach($ids as $id){
  37.     array_push($only_id,$id[1]);
  38.     file_put_contents("ids.txt",$id[1]."\n",FILE_APPEND);
  39.     file_put_contents("idsn.txt",$id[0]." -> ".$id[1]."\n",FILE_APPEND);
  40. }
  41.  
  42. $passo = 50;
  43. $pos = 0;
  44. while($pos<=count($ids)){
  45.     echo($pos."/".count($ids)."\n");
  46.     $request = implode(",",array_slice($only_id,$pos,$passo));
  47.     //echo("https://graph.facebook.com/v2.8/picture?redirect=0&ids=$request&access_token=$at\n");
  48.     $resp = file_get_contents("https://graph.facebook.com/v2.8/picture?redirect=0&ids=$request&access_token=$at",false,$context);
  49.     echo('-');
  50.     $resp = json_decode($resp,true);
  51.     foreach(array_slice($only_id,$pos,$passo) as $x){
  52.         echo('.');
  53.         file_put_contents("urls.txt",$resp[$x]["data"]["url"]."\n",FILE_APPEND);
  54.         $tmp = explode("/",$resp[$x]["data"]["url"]);
  55.         file_put_contents("urlsid.txt",$tmp[substr_count($resp[$x]["data"]["url"],"/")]." ".$x.".jpg\n",FILE_APPEND);
  56.         //file_put_contents("pics/$x.jpg",file_get_contents($resp[$x]["data"]["url"],false,$context));
  57.     }
  58.     echo('\n');
  59.     $pos += $passo;
  60. }
  61.  
  62. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement