-
Notifications
You must be signed in to change notification settings - Fork 221
Account Activity
linvi edited this page Aug 11, 2018
·
10 revisions
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.
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 :
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
var consumerOnlyCredentials = new ConsumerOnlyCredentials("CONSUMER_TOKEN", "CONSUMER_SECRET")
{
ApplicationOnlyBearerToken = "BEARER_TOKEN"
};
WebhookServerInitialization(app, consumerOnlyCredentials);
}
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);