How to check whether user is following an another user in twitter with Twitter API and TweetSharp

When you have the required keys and tokens you can check whether the user is following another user in twitter by using the Twitter API. I am using TweetSharp c# library to perform this task. I have tried with below code and worked for me. If you ever want to do it, try using below code segment.

_consumerKey = Your consumer key
_consumerSecret = Your consumer secret
_token = Authorized token
_tokenSecret = Token secret
TwitterService service = new TwitterService(_consumerKey, _consumerSecret);
service.AuthenticateWith(_token, _tokenSecret);
var user =  service.VerifyCredentials(new VerifyCredentialsOptions());
var twitterFriendship = service.GetFriendshipInfo(new GetFriendshipInfoOptions() { SourceScreenName = user.ScreenName, TargetScreenName = "profileName goes here" });

Now you have the required object and you check it using below condition.

(twitterFriendship.Relationship.Source.Following && twitterFriendship.Relationship.Target.FollowedBy)?true:false;

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.