twittertweetsharp

How to check whether user is following me not using TweetSharp.TwitterService.ListFollowers()


Is there some function in TweetSharp that could be used in a similar way to my 'IsFollowingMe' below?

I'd like to check whether a user is following me before I attempt to send some private message.

TweetSharp.TwitterService service;
string screenName = "@some_one";
string someMessage = "Some Message";

if (service.IsFollowingMe(screenName))
{
       service.SendDirectMessage(screenName, someMessage);
   else
       NotifyThatSendingNotPossible();
}

First option to such approach is to use:

TweetSharp.TwitterService service;
TwitterCursorList<TwitterUser> followers = service.ListFollowers();

and then iterate through the result to find out if user is following my account. But this will eventually be ineffective when there are a lot of followers.

Another option is to execute service.SendDirectMessage and then check if the result is null or not. I tested such approach with success - however my application logic prefers to check in advance if sending is possible and based on this information should do different actions.


Solution

  • The answer is as follows:

    TweetSharp.TwitterService service;
    string fromUser = "@mr_sender";
    string toUser = "@some_one";
    string someMessage = "Some Message";
    
    TweetSharp.TwitterFriendship friendship = 
        service.GetFriendshipInfo(fromUser, toUser);
    
    if (friendship.Relationship.Source.CanDirectMessage.HasValue &&
       friendship.Relationship.Source.CanDirectMessage.Value)
    {
        service.SendDirectMessage(screenName, someMessage);
    }
    else
    {
        NotifyThatSendingNotPossible();
    }