Skip to content

Account Activity

linvi edited this page Aug 11, 2018 · 10 revisions

Introduction

Account Activity is Twitter replacement of the old User Stream. It uses Webhooks that Twitter uses to push events to your https server.

To learn more on how to use Twitter Webhooks please go here.

Listen to user events

Before you can use Account Activity, you will need to register the Tweetinvi middeware for your AspNet project. When you do so you will use a WebhookConfiguration that will reuse here.

Tweetinvi middleware initialization can be done as followed :

private static void WebhookServerInitialization(IApplicationBuilder app, IConsumerOnlyCredentials consumerOnlyCredentials)
{
    Plugins.Add<WebhooksPlugin>();

    WebhookConfiguration = new WebhookConfiguration(consumerOnlyCredentials);

    app.UseTweetinviWebhooks(WebhookConfiguration);
}

On a server configured with Tweetinvi's webhooks, the registration to an Account Activity event is as easy as the following.

var activityStream = Stream.CreateAccountActivityStream(subscription.UserId);

activityStream.TweetCreated += (sender, args) =>
{
    var tweet = args.Tweet;
    Console.WriteLine($"Tweet {tweet.Id} has just been published!");
};

WebhookConfiguration.AddActivityStream(activityStream);
Clone this wiki locally