Quantcast
Channel: Tweetinvi a friendly Twitter C# library
Viewing all articles
Browse latest Browse all 4126

New Post: How to run a code when a given user tweets something?

$
0
0
Hi,

Can I specify which user to fetch tweets from?

Tweetinvi does not provide this feature by default because it is not provided by Twitter.
All depends on what you want to do. If you wish to receive the tweets from users that you are following, you need to use the UserStream and use the code above.
If you want to limit the scope of users you want to follow, just create a list of users you want to follow and check if they sent a message or not.

Here is the updated code :
IToken token = new Token("xxx", "xxx", "xxx", "xxx"); // Set your credentials here.
List<IUser> myFriendsToUpdate = new List<IUser>
{
    new User("myFriend1"),
    new User("myFriend2")
};

IUserStream us = new UserStream();
us.TweetCreatedByAnyone += (sender, args) =>
{
    var senderScreenName = args.Value.Creator.ScreenName;
    if (myFriendsToUpdate.Select(x => x.ScreenName).Contains(senderScreenName))
    {
        Console.WriteLine("Tweet '{0}' created!", args.Value.Text);
    }
};
us.StartStream(token);
I think this is a good suggestion and will implement this feature for the future version of the UserStream (but not in the nearby future).
I have consequently added a feature to the list of work items that you can find here : https://tweetinvi.codeplex.com/workitem/1936.

And can I just use Twitter Application Credentials (consumer key, access token etc.) instead of user credentials?

No you can't and never will be able to because Twitter requires the user to provide both the Application and the User credential. There is now way to only provide the application credentials for this kind of feature.

Hope this helps.
Kind Regards,
Linvi

Viewing all articles
Browse latest Browse all 4126

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>