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 o开发者_运维技巧f 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.
The exception is being thrown as the user your adding, you're already following. You'll need to either:
- Check if your already following that user, then follow
- Wrap the
var u.ts.FollowerUser(..)
in a try/catch so the loop will continue
精彩评论