forked from pinceladasdaweb/Twitterbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
68 lines (57 loc) · 2.55 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Twitterbot</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="jumbotron">
<div class="container">
<h1>Twitterbot</h1>
<p>A simple twitter bot script written in PHP.</p>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-12">
<?php
require "inc/twitter_credentials.php";
require "inc/Database.php";
require "vendor/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;
$pdo = Database::connect();
$getTweets = $pdo->prepare("SELECT *, RAND() as rand FROM tweets ORDER BY rand LIMIT 1");
$getTweets->execute();
if($getTweets->rowCount() > 0) {
while ($row = $getTweets->fetch()) {
$tweet = $row['tweet'];
}
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$content = $connection->get('account/verify_credentials');
$connection->post('statuses/update', array('status' => $tweet));
if ($connection->getLastHttpCode() === 200) {
echo '<p><strong>Your latest tweet:</strong> '. $tweet .'</p>'.PHP_EOL;
} else {
echo '<p><strong>Error:</strong> A problem ocorrud. You filled your Twitter credentials correctly? Or walk abusing the Twitter API?</p>'.PHP_EOL;
}
} else {
echo '<p><strong>Error:</strong> You have no tweets registered in the database or not filled data connection properly.</p>'.PHP_EOL;
}
Database::disconnect();
?>
</div>
</div>
<hr>
<footer>
<p>© Pinceladas da Web <?php echo date('Y'); ?></p>
</footer>
</div>
</body>
</html>