Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Questo script in php "dumpa" le informazioni sui post di uno specifico gruppo di facebook in un database MYSQL
- //E' stato scritto "al volo" in poche ore ed è quindi scritto male. Non escludo che in futuro ne pubblicherò una versione aggiornata.
- //
- //Enrico 'tpaper' Ronconi - 28 may 2015 - V 10^(-9) ALPHA
- //
- //PS: Per poterla usare è necessario un token valido di un utente che ha accesso al feed del gruppo.
- //PPS: Se usate lo script per analizzare gruppi "famosi" o di cui sono membro gradirei essere citato come autore dello script. Voi potete prendervi i meriti per l'elaborazione successiva dei dati.
- $count = 0;
- $MYSQL_host = 'localhost';
- $MYSQL_username = 'SALANI';
- $MYSQL_password = 'SALANI';
- $MYSQL_database = 'fbstat';
- $MYSQL = @new mysqli($MYSQL_host, $MYSQL_username, $MYSQL_password, $MYSQL_database); //Start connection
- if($MYSQL->connect_error) die('Error while connection (Errno: '.$MYSQL->connect_errno.' - '.$MYSQL->connect_error.")!\nAborted\n"); echo("Succesfully connected!\n");
- $MYSQL->set_charset("utf8");
- $mysqli = $MYSQL;
- $request_url ="https://graph.facebook.com/
- SALANI/
- feed?
- fields=from,message,likes.limit(0).summary(true),comments.limit(1).summary(true)&
- limit=800&
- access_token=SALANI";
- $prossimo = req($request_url);
- while($prossimo != NULL) {
- $prossimo = req($prossimo);
- }
- echo("\n\nTot: $count");
- function req($url){
- global $mysqli;
- global $count;
- $requests = file_get_contents(str_replace(array("\r", "\n"), "", $url));
- //$requests = file_get_contents($url);
- $fb_response = json_decode($requests);
- $messaggi = $fb_response->{"data"};
- if(count($messaggi) == 0) return NULL;
- foreach ($messaggi as $messaggio) {
- $count = $count +1;
- $c1 = $messaggio->{"id"};
- $c2 = $messaggio->{"from"}->{"id"};
- $c3 = $mysqli->real_escape_string($messaggio->{"from"}->{"name"});
- $c4 = $messaggio->{"likes"}->{"summary"}->{"total_count"};
- $c5 = $messaggio->{"comments"}->{"summary"}->{"total_count"};
- $c6 = explode("+",str_replace("T", " ", $messaggio->{"updated_time"}));
- $c6 = $c6[0];
- if(array_key_exists(0,$messaggio->{"comments"}->{"data"})){
- if($messaggio->{"comments"}->{"summary"}->{"order"} != "chronological") die("err chrono\n");
- $c7 = '"'.$messaggio->{"comments"}->{"data"}[0]->{"from"}->{"id"}.'"';
- $c8 = '"'.$mysqli->real_escape_string($messaggio->{"comments"}->{"data"}[0]->{"from"}->{"name"}).'"';
- } else {
- $c7 = "NULL";
- $c8 = "NULL";
- }
- $out = $mysqli->query("INSERT INTO degradoland
- (post_id,user_id,user_name,like_n,comment_n,date,first_com_user_id,first_com_user_name)
- VALUES
- (\"$c1\", \"$c2\", \"$c3\", $c4, $c5, \"$c6\", $c7, $c8);
- ");
- if(!$out) {die("query err ".$mysqli->error." \n");}
- $lastdate = $messaggio->{"updated_time"};
- }
- echo("n: $count - $lastdate\n");
- return $fb_response->{"paging"}->{"next"};
- }
- $mysqli->close()
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement