-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathexample.php
70 lines (53 loc) · 1.67 KB
/
example.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<?php
// Require J7mbo's TwitterAPIExchange library (used to retrive the tweets)
require_once('vendor/j7mbo/twitter-api-php/TwitterAPIExchange.php');
// Require our TwitterTextFormatter library
require_once('TwitterTextFormatter.php');
// Use the class TwitterTextFormatter
use Netgloo\TwitterTextFormatter;
// Set here your twitter application tokens
$settings = array(
'consumer_key' => 'CONSUMER_KEY',
'consumer_secret' => 'CONSUMER_SECRET',
// These two can be left empty since we'll only read from the Twitter's
// timeline
'oauth_access_token' => '',
'oauth_access_token_secret' => '',
);
// Set here the Twitter account from where getting latest tweets
$screen_name = 'netglooweb';
// Get timeline using TwitterAPIExchange
$url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$getfield = "?screen_name={$screen_name}";
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$user_timeline = $twitter
->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
$user_timeline = json_decode($user_timeline);
// Print each tweet using TwitterTextFormatter to get the HTML text
echo "<ul>";
foreach ($user_timeline as $user_tweet) {
echo "<li>";
echo TwitterTextFormatter::format_text($user_tweet) . "<br/>";
// Print also the tweet's image if is set
if (isset($user_tweet->entities->media)) {
$media_url = $user_tweet->entities->media[0]->media_url;
echo "<img src='{$media_url}' width='150px' />";
}
echo "</li>";
}
echo "</ul>";
?>
<p>
Visit our web site at <a href="http://netgloo.com">http://netgloo.com</a>
</p>
</body>
</html>