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 Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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