-
Notifications
You must be signed in to change notification settings - Fork 59
/
FacebookAutoPilot.php
executable file
·113 lines (86 loc) · 3.67 KB
/
FacebookAutoPilot.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
102
103
104
105
106
107
108
109
110
111
112
113
<?php
include_once("config.php");
require_once __DIR__ . "/lib/facebook-php-sdk-v4-4.0-dev/autoload.php"; //include autoload from SDK folder
use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\GraphUser;
use Facebook\FacebookRedirectLoginHelper;
FacebookSession::setDefaultApplication($appId , $appSecret);
$helper = new FacebookRedirectLoginHelper($redirectURL);
try {
$session = $helper->getSessionFromRedirect();
}
catch(FacebookRequestException $ex) {
die("FacebookRequestException: " . $ex->getMessage());
}
catch(\Exception $ex) {
die("Exception: " . $ex->getMessage());
}
// if I'm logged in and ready to post on group pages
if ($session) {
$groups = (new FacebookRequest(
$session,
'GET',
'/me/groups'
))->execute()->getGraphObject()->asArray();
$_SESSION["groups"] = $groups["data"];
echo "Total Groups: " . count($groups["data"]);
if(isset($_SESSION["groups"])) {
echo '<br>Hi, you are logged into Facebook [ <a href="?logOut=1">Log Out</a> ] ';
writeToLogs("\n\n\nPosting to Facebook Walls [" . date("Y-m-d h:i:sa", time()) . "]");
writeToLogs("\n----------------------------------------");
for($i = 0; $i < $maxGroups; $i++) {
if($_SESSION["groups"][$i]) {
$group = $_SESSION["groups"][$i];
// exclude certain groups
$continue = true;
if (strpos($group->name,'Science') !== false) { $continue = false; }
else if (strpos($group->name,'UCC') !== false) { $continue = false; }
else if(strpos($group->name,'Udemy') !== false) { $continue = false; }
else if (strpos($group->name,'JCI') !== false) { $continue = false; }
else if (strpos($group->name,'Cappamore') !== false) { $continue = false; }
if($continue) {
$postURL = '/' . $group->id . '/feed';
$message = array(
'message' => 'Hey guys!
Thought I’d give something back to the community :)
Check out v2 of AppLandr, which allows you to generate beautifully crafted (free or paid) landing pages for your mobile applications! And of course it’s on Product Hunt!
Would love to hear your thoughts!
http://applandr.com',
'link' => 'http://applandr.com',
'picture' => 'http://www.applandr.com/lib/images/dark.png'
);
$groupUrl = "http://www.facebook.com/groups/" . $group->id;
try {
$postRequest = new FacebookRequest($session, 'POST', $postURL, $message);
$postRequest->execute();
$logMessage = "\nSUCCESS: posting message to $groupUrl";
writeToLogs($logMessage);
echo "<br>SUCCESS: posting message to <a href='$groupUrl' target='_blank'>" . $group->name . "</a>";
}
catch(FacebookRequestException $ex) {
$logMessage = "\nFAIL: posting message to " . $groupUrl . " with ERROR: " . $e->getMessage();
writeToLogs($logMessage);
echo "<br>FAIL: posting message to <a href='$groupUrl' target='_blank'>" . $group->name . "</a> with ERROR: " . $e->getMessage();
}
$delayTime = rand($minDelayTime, $maxDelayTime);
sleep($delayTime);
}
}
}
}
} else {
$loginURL = $helper->getLoginUrl( array( 'scope' => $requiredPermissions ) );
echo '<a href="'.$loginURL.'">Login with Facebook</a>';
}
if(isset($_GET["logOut"]) && $_GET["logOut"]==1){
unset($_SESSION["groups"]);
header("location: ". $redirectURL);
}
function writeToLogs($textToWrite) {
$currentfile = "logs.txt";
$updatedFile = file_get_contents($currentfile);
$updatedFile .= $textToWrite;
file_put_contents($currentfile, $updatedFile);
}
?>