Kodlama kisisel olduguu icin, ne sintaks, ne testler hic bir sey yoktur. Sadece isinizi gorsun yeterli. :)
Oncelikle mesajlari Facebook API'si ile 30'arli gruplar halinde cekiyoruz. Sonrasinda onlari PHP tarafinda birlestiriyoruz.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Should run under Graph API Explorer | |
SELECT thread_id, recent_authors, snippet FROM thread WHERE folder_id = 0 AND snippet = 'LAST MSG' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var last_page = 217; | |
var current = 0; | |
function fetch(){ | |
var xmlhttp = new XMLHttpRequest(); | |
xmlhttp.onreadystatechange = function () { | |
if (xmlhttp.readyState == 4) { | |
var msg = (xmlhttp.responseText); | |
var data = new FormData(); | |
data.append('data', msg); | |
var xhr = new XMLHttpRequest(); | |
xhr.open('POST', 'SOMEWHERE/fetch.php', true); | |
xhr.onload = function () { | |
}; | |
xhr.send(data); | |
if (current > last_page) { | |
console.log('Finished.'); | |
return; | |
} | |
current++; | |
fetch(); | |
} | |
}; | |
xmlhttp.open("GET", "https://graph.facebook.com/fql?q=SELECT%20author_id%2C%20body%2C%20created_time%20FROM%20message%20%0AWHERE%20thread_id%20%3D%20%271565550332685%27%20%0AORDER%20BY%20created_time%20ASC%0ALIMIT%20" + current * 30 + "%2C%2030&format=json&suppress_http_code=1&access_token=TOKEN_COMES_HERE", true); | |
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); | |
xmlhttp.send(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$data = $_REQUEST['data']; | |
file_put_contents(__DIR__ . '/chats2/'. microtime(true) , $data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// requies PHP5.4 | |
$messages = []; | |
foreach (glob('chats2/*') as $file) { | |
/*if (filesize($file) < 120) { | |
unlink($file); | |
}*/ | |
$data = json_decode(file_get_contents($file), true); | |
$messages = array_merge($messages, $data['data']); | |
} | |
$time []; | |
foreach ($messages as $message) { | |
$author[] = $message['author_id']; | |
$time[] = $message['created_time']; | |
$msg[] = $message['body']; | |
} | |
array_multisort($time, SORT_ASC, $messages); | |
foreach ($messages as $msg) { | |
if ($msg['author_id'] == 'YOUR FB ID') { | |
$sender = 'YOURNAME'; | |
} | |
else { | |
$sender = 'FRIENDNAME'; | |
} | |
echo '<b>', $sender, ' </b>', '<i>', date('d.m.Y H:i', $msg['created_time']), '</i><br>', $msg['body'], '<br><br>'; | |
} |
No comments:
Post a Comment