-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
93 lines (83 loc) · 2.77 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
require "facebook.php";
$contents;
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => 'xxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxx',
));
echo 'Read Mailbox';
echo "<br/><br/><br/>";
$full = array();//array to keep track of all messages
function puddinFile($stringy){
$file = fopen("meep.csv","a") or die("can't open file");
fwrite($file,$stringy);
fclose($file);
}
function readMail($date,$facebook){
$n = 0;
while($n < 80000){//loop constantly (for some reason fb doesn't like it when you set while to 1)
$fql = "SELECT created_time, message_id, body, author_id FROM message WHERE thread_id = 376659462449930 AND created_time > $date order by created_time asc limit 30 OFFSET $n";//offset is set to changing var
try {
$result = $facebook->api(array(
'method' => 'fql.query',
'query' =>$fql,
));
}
catch(FacebookApiException $e){
$e_type = $e->getType();
echo 'Got an ' . $e_type . ' while posting';
echo $e;
if($e == "Exception: Calls to this api have exceeded the rate limit."){
echo "graceful exit";
echo "<br>$n<br>";
exit($full);
}
}
$n+=30;//add 30 to offset
$rSize = sizeof($result);
for($i=0;$i<$rSize;$i++){//format all parts of returned array to write to string
$author = $result[$i]['author_id'];
$author = (string)$author;
$message = $result[$i]['body'];
$message = (string)$message;
$id = $result[$i]['message_id'];
$id = (string)$id;
$search = array('"',"\n");
$message = str_replace($search, ',', $message);
$message = '"'.$message.'"';
$date = $result[$i]['created_time'];
$date = (string)$date;
$fString = $id.",".$author.",".$message.",".$date."\n";//final string
puddinFile($fString);//you will timeout before you writeout. and the try catch isn't always reliable as i've found.
//but that may be just because of my shitty server, i dono.
}
$full = array_merge($full,$result);//not necessary but just for printing purposes
}
}
//opens and reads the last line until the third \n which is the start of the last line.
//adds the date to the fql query that needs to start over.
$sFile = fopen("meep.csv","r");
fseek($sFile, -1, SEEK_END);
$pos = ftell($sFile);
$LastLine = "";
$secondLine=false;
$newliner = 0;
while(($secondLine == false) && ($pos > 0)){
$C = fgetc($sFile);
if($C=="\n"){
$newliner +=1;
}
if($newliner==3){
$secondLine=true;
}
$LastLine = $C.$LastLine;
fseek($sFile,$pos--);
}
$fromDate = explode(',',$LastLine,4);//splode
$date = $fromDate[3];//get da date
readMail($date,$facebook);//loopit
echo "<pre>";
print_r($full); //for pretty printing if you desire it.
echo "</pre>";
?>