开发者

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:

  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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜