forked from jliman/SEOStat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch_facebook.php
101 lines (81 loc) · 2.87 KB
/
fetch_facebook.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
94
95
96
97
98
99
100
101
<?php
require_once('inc/db.php');
require_once('inc/helper.php');
require_once('inc/fetch.php');
$fetchFacebook = true;
$saveToDB = true;
echo 'Start fetch Facebook: '.date("Y-m-d H:i:s").'<br>';
foreach ($accounts as $account) {
echo 'Get stat for: '.$account['url'].' - '.date("Y-m-d H:i:s").'<br>';
//get facebook page stat
if ($fetchFacebook && $account['fb_pageid'] != '') {
facebookLogin($account['ga_username'], $account['ga_passwd']);
$ch = getCURLResource();
curl_setopt($ch, CURLOPT_URL, "http://www.facebook.com/business/insights/json.php?id=".$account['fb_pageid']."&reports=1");
$buf2 = curl_exec ($ch);
curl_close($ch);
//$tempArr = explode('or (;;);',$buf2);
//$tempArr = json_decode($tempArr[1], true);
//echo '<pre>'.$buf2.'</pre>';
$result = array();
$tempArr = explode('{"Total Interactions":[[',$buf2);
$tempArr = explode(']]},{"Comments"',$tempArr[1]);
$tempArr = explode('],[',$tempArr[0]);
for ($i = 0; $i < sizeof($tempArr); $i++) {
$tempArr[$i] = explode(',',$tempArr[$i]);
}
$result['Total Interactions'] = $tempArr;
$tempArr = explode('{"Comments":[[',$buf2);
$tempArr = explode(']]},{"Wall Posts"',$tempArr[1]);
$tempArr = explode('],[',$tempArr[0]);
for ($i = 0; $i < sizeof($tempArr); $i++) {
$tempArr[$i] = explode(',',$tempArr[$i]);
}
$result['Comments'] = $tempArr;
$tempArr = explode('{"Wall Posts":[[',$buf2);
$tempArr = explode(']]},{"Likes"',$tempArr[1]);
$tempArr = explode('],[',$tempArr[0]);
for ($i = 0; $i < sizeof($tempArr); $i++) {
$tempArr[$i] = explode(',',$tempArr[$i]);
}
$result['Wall Posts'] = $tempArr;
$tempArr = explode('{"Likes":[[',$buf2);
$tempArr = explode(']]},',$tempArr[1]);
$tempArr = explode('],[',$tempArr[0]);
for ($i = 0; $i < sizeof($tempArr); $i++) {
$tempArr[$i] = explode(',',$tempArr[$i]);
}
$result['Likes'] = $tempArr;
$ch = getCURLResource();
curl_setopt($ch, CURLOPT_URL, "http://www.facebook.com/business/insights/json.php?id=".$account['fb_pageid']."&reports=2");
$buf2 = curl_exec ($ch);
curl_close($ch);
$result2 = array();
$tempArr = explode('{"Total Likes":[[',$buf2);
$tempArr = explode(']]},{"Hidden From News Feed"',$tempArr[1]);
$tempArr = explode('],[',$tempArr[0]);
for ($i = 0; $i < sizeof($tempArr); $i++) {
$tempArr[$i] = explode(',',$tempArr[$i]);
}
$result2['Total Fans'] = $tempArr;
$tempArr = explode('{"Hidden From News Feed":[[',$buf2);
$tempArr = explode(']]},',$tempArr[1]);
$tempArr = explode('],[',$tempArr[0]);
for ($i = 0; $i < sizeof($tempArr); $i++) {
$tempArr[$i] = explode(',',$tempArr[$i]);
}
$result2['Unsubscribed Fans'] = $tempArr;
/*
echo '<pre>';
print_r($result);
print_r($result2);
echo '</pre>';
*/
if ($saveToDB) {
saveFacebookStat($account,$result,$result2);
}
facebookLogout();
}
}
echo 'End fetch Facebook: '.date("Y-m-d H:i:s").'<br>';
?>