-
Notifications
You must be signed in to change notification settings - Fork 5
/
feed.php
85 lines (69 loc) · 2.46 KB
/
feed.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
<?php
//include the Facebook PHP SDK
include_once 'facebook.php';
include_once 'csv_writter.php';
include_once 'config.inc.php';
if(isset($_POST['load'])){
//instantiate the Facebook library with the APP ID and APP SECRET
$facebook = new Facebook(array(
'appId' => FACEBOOK_API,
'secret' => FACEBOOK_SECRET,
'cookie' => true
));
//get the news feed of the active page using the page's access token
$page_feed = $facebook->api(
'/'.$_POST['page_id'].'/feed',
'GET',
array(
'access_token' => $_SESSION['active']['access_token'],
'limit'=>10000000
)
);
$filename = $_POST['page_id'].'.csv';
$filename_comments = $_POST['page_id'].'_comments.csv';
$file_post = new CSV($filename);
$file_post_comments = new CSV($filename_comments);
}
?>
<html>
<body>
<form action="feed.php" method="post">
<input type="text" name="page_id"/>
<input type="submit" value="Load" name="load"/>
</form>
</body>
<div>
<?php
if(is_array($page_feed))
{
$file_post->open();
$file_post_comments->open();
$file_post->save_header(array('post_id','from_name','from_id','message','post_type','created_time','created_updated'));
$file_post_comments->save_header(array('post_id','comment_id','comment_from_name','message','comment_created'));
//print_r($page_feed);
foreach($page_feed['data'] as $post){
echo "ID:".$post['id']."<br>";
echo "FROM NAME:".$post['from']['name']."<br>";
echo "FROM ID:".$post['from']['id']."<br>";
echo "MESSAGE:".$post['message']."<br>";
echo "TYPE:".$post['type']."<br>";
echo "CREATED_TIME:".$post['created_time']."<br>";
echo "UPDATED_TIME:".$post['updated_time']."<br>";
$file_post->save_line(array($post['id'],$post['from']['name'],$post['from']['id'],$post['message'],$post['type'],$post['created_time'],$post['updated_time']));
if(is_array($post['comments']['data'])){
foreach ($post['comments']['data'] as $comment){
$file_post_comments->save_line(array($post['id'],$comment['id'],$comment['from']['name'],$comment['message'],$comment['created_time']));
echo "------------------------------------------------<br>";
echo " COMMENT ID:".$comment['id']."<br>";
echo " COMMENT FROM:".$comment['from']['name']."<br>";
echo " COMMENT:".$comment['message']."<br>";
echo " COMMENT CREATED:".$comment['created_time']."<br>";
}}
echo '-------------------------------------------<br>';
}
$file_post->close();
$file_post_comments->close();
}
?>
</div>
</html>