-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwitter.php
More file actions
62 lines (47 loc) · 1.81 KB
/
Copy pathtwitter.php
File metadata and controls
62 lines (47 loc) · 1.81 KB
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
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Twitter App</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div>
Search <img src="twitter.png" alt="twitter image"><span>Twitter</span> for: <br>
<form method="get" action="" class="search-bar">
<input type="search" name="keyword" pattern=".*\S.*" required="required">
<button class="search-btn" type="submit">
<span>Search</span>
</button>
</form>
<?php
// ini_set('display_errors','1');
require_once('TwitterAPIExchange.php');
$settings = array(
'oauth_access_token' => "access_token",
'oauth_access_token_secret' => "access_token_secret",
'consumer_key' => "consumer_key",
'consumer_secret' => "consumer_secret"
);
$url = "https://api.twitter.com/1.1/search/tweets.json";
$requestMethod = "GET";
$getfield = '?q='.$_GET['keyword'].'&result_type=recent&count=10';
$twitter = new TwitterAPIExchange($settings);
$string = json_decode($twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest(),$assoc = TRUE);
if(array_key_exists("errors", $string)) {echo "<h3>Sorry, there was a problem.</h3><p>Twitter returned the following error message:</p><p><em>".$string[errors][0]["message"]."</em></p>";exit();}
foreach($string['statuses'] as $items)
{
echo "Time and Date of Tweet: ".$items['created_at']."<br />";
echo "Tweet: ". $items['text']."<br />";
echo "Tweeted by: ". $items['user']['name']."<br />";
echo "Screen name: ". $items['user']['screen_name']."<br />";
echo "Followers: ". $items['user']['followers_count']."<br />";
echo "Friends: ". $items['user']['friends_count']."<br />";
echo "Listed: ". $items['user']['listed_count']."<br /><hr />";
}
?>
</div>
</body>
</html>