-
Notifications
You must be signed in to change notification settings - Fork 0
/
serbfactposter.php
63 lines (40 loc) · 1.67 KB
/
serbfactposter.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
<?php
// Moving to abes twit auth
require_once "vendor/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;
require "assets/mitroserbiafacts.php";
## Managing the index count invrementally in a sep text file
$storageFile = "serbfactsindex.txt";
if (!file_exists($storageFile) || file_get_contents($storageFile) >= count($serbfacts)) {
file_put_contents($storageFile, "0");
}
$count = file_get_contents($storageFile);
echo $count;
file_put_contents($storageFile, ($count + 1));
echo $serbfacts[$count];
// // local settings for twitter api connection - with config
// require_once('config.php');
// $settings = array(
// 'oauth_access_token' => ACCESS_TOKEN,
// 'oauth_access_token_secret' => ACCESS_TOKEN_SECRET,
// 'consumer_key' => CONSUMER_KEY,
// 'consumer_secret' => CONSUMER_SECRET
// );
// $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
// Production settings for api connection - GH Actions
$ACCESS_TOKEN = getenv("ACCESS_TOKEN");
$ACCESS_TOKEN_SECRET = getenv("ACCESS_TOKEN_SECRET");
$CONSUMER_KEY = getenv("CONSUMER_KEY");
$CONSUMER_SECRET = getenv("CONSUMER_SECRET");
$connection = new TwitterOAuth($CONSUMER_KEY, $CONSUMER_SECRET, $ACCESS_TOKEN, $ACCESS_TOKEN_SECRET);
// Sending tweets from the info file
$status = $serbfacts[$count];
$result = $connection->post("statuses/update", ["status" => $status]);
if ($connection->getLastHttpCode() == 200) {
echo "Your Tweet posted successfully.";
print_r($result);
} else {
echo $connection->getLastHttpCode();
print_r($result);
echo 'error: ' . $result->errors[0]->message;
}