Yury
Yury

Reputation: 1

Follow user using TweetSharp

I use following code to follow user:

TwitterService ts = new TwitterService(TWI_CONSUMER_KEY, TWI_CONSUMER_SECRET);
ts.AuthenticateWith(token.Token, token.Secret);

var users = ts.SearchForUser(query); //Get list of users by query
//...
foreach (var user in users) 
{
    var u = ts.FollowUser(user.Id); //Follow user
}

and get exception:

System.ArgumentException: Item with the same key has already been added

Are there any mistakes? Please help me.

Upvotes: 0

Views: 1583

Answers (1)

Jason Jong
Jason Jong

Reputation: 4330

The exception is being thrown as the user your adding, you're already following. You'll need to either:

  1. Check if your already following that user, then follow
  2. Wrap the var u.ts.FollowerUser(..) in a try/catch so the loop will continue

Upvotes: 1

Related Questions