This repository has been archived by the owner on Apr 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax.php
61 lines (39 loc) · 1.12 KB
/
ajax.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
<?php
require_once 'config.php';
if (!isset($_GET['screen_name'])) {
echo "No user specified.";
die();
}
$tmhOAuth -> request(
"GET",
$tmhOAuth -> url("1/friends/ids"),
array("screen_name" => $_GET['screen_name'])
);
$results = $tmhOAuth -> response['response'];
$code = $tmhOAuth -> response['code'];
if ($code !== 200) {
echo "Error: Cannot connect to Twitter API";
die();
}
$decoded = json_decode($results,true);
$flag = false;
while (!$flag) {
$selecteduserid = array_rand($decoded[ids]);
$friendID = $decoded[ids][$selecteduserid];
$array['id'] = $friendID;
$tmhOAuth -> request(
"GET",
$tmhOAuth -> url("1/users/show"),
array("user_id" => $friendID)
);
$result = $tmhOAuth -> response['response'];
$decoded = json_decode($result,true);
if (($decoded["protected"] !== true) and ($decoded[friends_count] > 0) and ($decoded[statuses_count] > 0)) {
$flag = true;
}
}
$array['screen_name'] = $decoded[screen_name];
$array['profile_image_url'] = str_replace("_normal","_reasonably_small",$decoded[profile_image_url]);
$array['tweet'] = $decoded[status][text];
print_r(json_encode($array));
?>