-
Notifications
You must be signed in to change notification settings - Fork 0
/
User.php
104 lines (77 loc) · 2.99 KB
/
User.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
require_once 'twitteroauth.php';
require_once 'keys.php';
class User {
public $id;
public $name;
public $latest_tweet_id;
public $latest_tweet_text;
public $latest_mention_id;
public $latest_mentioner;
public $latest_mentioner_name;
function __construct() {
//make connection
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_SECRET);
//establish identity
$creds = $connection->get('account/verify_credentials');
$this->id = $creds->{'id'};
$this->name = $creds->{'screen_name'};
//latest tweets and mentions
$tweets = $connection->get('statuses/user_timeline');
$this->latest_tweet_id = $tweets[0]->{'id_str'};
$list_of_mentions = $connection->get('statuses/mentions', array('since_id' => $this->latest_tweet_id)); //
$this->latest_mentioner = $list_of_mentions[0]->{'user'};
$this->latest_tweet_text = $tweets[0]->{'text'};
//get the latest mention and who made it
$this->latest_mention_id = $list_of_mentions[0]->{'id_str'};
$this->latest_mentioner_name = '@' . $this->latest_mentioner->{'screen_name'};
}
function hasNewMention() {
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_SECRET);
$tweets = $connection->get('statuses/user_timeline');
$latest_tweet_id = $tweets[0]->{'id_str'};
$list_of_mentions = $connection->get('statuses/mentions', array('since_id' => $latest_tweet_id)); //
$latest_mention_id = $list_of_mentions[0]->{'id_str'};
if (!$latest_mention_id) {
return FALSE;
} else if ($latest_mention_id) {
return TRUE;
}
}
function makePost($status_code, $message, $reply_to_id) {
switch ($status_code) {
case 3:
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_SECRET);
$connection->post('statuses/update', array('status' => $message, 'in_reply_to_status_id' => $reply_to_id));
break;
case 2:
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_SECRET);
$connection->post('statuses/update', array('status' => $message));
break;
case 1:
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_SECRET);
$connection->post('statuses/update', array('status' => $message));
break;
case 0:
break;
default:
break;
}
}
function getRandomFriend() {
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_SECRET);
$friends_list = $connection->get('friends/ids');
$number_following = count($friends_list->{'ids'});
$friend_list_index = mt_rand(0, $number_following-1);
$friend_id = $friends_list->{'ids'}[$friend_list_index]; //"236992726";
$friend = $connection->get('users/lookup', array('user_id' => $friend_id));
$random_friend = "@" . $friend[0]->{'screen_name'};
return $random_friend;
}
function friendList() {
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_SECRET);
$friends_list = $connection->get('friends/ids');
return $friends_list;
}
}
?>