开发者

Follow user using TweetSharp

开发者 https://www.devze.com 2023-03-15 09:38 出处:网络
I use following code to follow user: TwitterService ts = new TwitterService(TWI_CONSUMER_KEY, TWI_CONSUMER_SECRET);

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

精彩评论

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