-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcursor.php
85 lines (70 loc) · 2.29 KB
/
cursor.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
<?php
require_once 'twitteroauth.php';
$oTwitter = new TwitterOAuth
('YOUR_TWITTER_APP_CONSUMER_KEY',
'YOUR_TWITTER_APP_CONSUMER_SECRET',
'YOUR_TWITTER_APP_OAUTH_TOKEN',
'YOUR_TWITTER_APP_OAUTH_SECRET');
//FULL FOLLOWERS ARRAY WITH CURSOR ( FOLLOWERS > 5000)
$e = 1;
$cursor = -1;
$full_followers = array();
do {
//SET UP THE URL
$follows = $oTwitter->get("followers/ids.json?screen_name=USERNAMEHERE&cursor=".$cursor);
$foll_array = (array)$follows;
foreach ($foll_array['ids'] as $key => $val) {
$full_followers[$e] = $val;
$e++;
}
$cursor = $follows->next_cursor;
} while ($cursor > 0);
echo "Number of followers:" .$e. "<br /><br />";
//FULL FRIEND ARRAY WITH CURSOR (FOLLOWING > 5000)
$e = 1;
$cursor = -1;
$full_friends = array();
do {
$follow = $oTwitter->get("friends/ids.json?screen_name=USERNAMEHERE&cursor=".$cursor);
$foll_array = (array)$follow;
foreach ($foll_array['ids'] as $key => $val) {
$full_friends[$e] = $val;
$e++;
}
$cursor = $follow->next_cursor;
} while ($cursor > 0);
echo "Number of following:" .$e. "<br /><br />";
//IF I AM FOLLOWING USER AND HE IS NOT FOLLOWING ME BACK, I UNFOLLOW HIM
$index=1;
$unfollow_total=0;
foreach( $full_friends as $iFollow )
{
$isFollowing = in_array( $iFollow, $full_followers );
echo $index .":"."$iFollow: ".( $isFollowing ? 'OK' : '!!!' )."<br/>";
$index++;
if( !$isFollowing )
{
$parameters = array( 'user_id' => $iFollow );
$status = $oTwitter->post('friendships/destroy', $parameters);
$unfollow_total++;
} if ($unfollow_total === 999) break;
}
echo "<br /><br />";
//IF USER IS FOLLOWING ME AND I AM NOT, I FOLLOW
$index=1;
$follow_total = 0;
foreach( $full_followers as $heFollows )
{
$amFollowing = in_array( $heFollows, $full_friends );
echo $index .":"."$heFollows: ".( $amFollowing ? 'OK' : '!!!' )."<br/>";
$index++;
if( !$amFollowing )
{
$parameters = array( 'user_id' => $heFollows );
$status = $oTwitter->post('friendships/create', $parameters);
$follow_total++;
} if ($follow_total === 999) break;
}
echo 'Unfollowed:'.$unfollow_total.'<br />';
echo 'Followed:'.$follow_total.'<br />';
?>