-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitter.php
63 lines (50 loc) · 2.01 KB
/
twitter.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
<?php
include_once 'twitterLink.php';
include 'twittertoken.php';
$url = 'https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=jamiekitson&count=10&include_rts=1&include_entities=1&tweet_mode=extended';
// $url = 'https://api.twitter.com/2/users/jamiekitson/timelines/reverse_chronological?tweet.fields=created_at&expansions=author_id&user.fields=created_at&max_results=5';
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer " . $twittertoken));
$response = curl_exec( $ch );
//print($response);
//return;
$tweets = json_decode($response);
foreach($tweets as $tweet)
{
if (is_array($tweet))
throw new Exception($response);
$date = strtotime($tweet->created_at);
$status = "";
if (property_exists($tweet, "retweeted_status"))
{
$tweet = $tweet->retweeted_status;
$status = "RT @".$tweet->user->screen_name.": ";
}
echo '<div class="twitterpost">';
$status .= $tweet->full_text;
expandURLs($tweet->entities->urls, $status);
if (property_exists($tweet->entities, "media"))
expandURLs($tweet->entities->media, $status);
echo linkify_twitter_status($status);
echo '<div class="twitterdate">';
echo statusLink($tweet->id_str, 'jamiekitson', date('D M d H:i', $date));
if ($tweet->in_reply_to_status_id != '')
{
echo statusLink($tweet->in_reply_to_status_id_str, $tweet->in_reply_to_screen_name, 'In reply to '.$tweet->in_reply_to_screen_name);
}
echo "</div></div>\n";
}
function statusLink($statusID, $userName, $linkText)
{
return sprintf('<a class="twitterdate" href="https://twitter.com/%s/statuses/%s">%s</a> ',
$userName, $statusID, $linkText);
}
function expandURLs($urls, &$stat)
{
foreach($urls as $url)
{
$stat = str_replace($url->url, $url->expanded_url, $stat);
}
}
?>