Created
November 11, 2011 11:15
-
-
Save skhatri/1357771 to your computer and use it in GitHub Desktop.
unfollow the unfollowers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
ConfigurationBuilder builder = new ConfigurationBuilder(); | |
builder.setOAuthAccessToken("configure") | |
.setOAuthAccessTokenSecret("these") | |
.setOAuthConsumerKey("params") | |
.setOAuthConsumerSecret("in twitter"); | |
//twitter4j | |
Twitter twitter = new TwitterFactory(builder.build()).getInstance(); | |
Map<String, String> safeList = new HashMap<String, String>(); | |
//list of twitusers who you want to put in safelist | |
safeList.put("creativjs", "330064669"); | |
safeList.put("chromedevrel", "278240271"); | |
safeList.put("HTML5Party", "332183653"); | |
safeList.put("ebidel", "14399709"); | |
safeList.put("agektmr", "3837171"); | |
IDs incoming = twitter.getFollowersIDs(-1); | |
System.out.println("Number of ops allowed in the next hour "+ incoming.getRateLimitStatus().getRemainingHits()); | |
Map<String, String> followersMap = new HashMap<String, String>(); | |
long follower[] = incoming.getIDs(); | |
for (int i=0; i<follower.length; i++) { | |
followersMap.put(String.valueOf(follower[i]), String.valueOf(follower[i])); | |
} | |
System.out.println("followers stored " + followersMap.size()); | |
IDs ids = twitter.getFriendsIDs(-1); | |
long following[] = ids.getIDs(); | |
System.out.println("I am following " + following.length); | |
System.out.println("Deleting the not reciprocating"); | |
int x = 0; | |
//do 100 ops in a batch | |
for (int i=0; x < 100; i++) { | |
if (!followersMap.containsKey(String.valueOf(following[i]))) { | |
try { | |
String screenName = twitter.lookupUsers(new long[]{following[i]}).get(0).getScreenName(); | |
System.out.print("Removing user "); | |
System.out.println(following[i] + " " + screenName); | |
if (!safeList.containsKey(screenName)) { | |
twitter.destroyFriendship(following[i]); | |
} else { | |
System.out.println("not removing friend "+ safeList.get(String.valueOf(following[i]))); | |
} | |
x++; | |
} catch (Exception e) { | |
System.err.println("error in getting not following list " + following[i]); | |
} | |
} | |
} | |
System.out.println("Queried " + x + " ids"); | |
System.exit(0); | |
} catch (TwitterException te) { | |
te.printStackTrace(); | |
System.out.println("Failed to get account settings: " + te.getMessage()); | |
System.exit(-1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
????