xdevplatform / Twitter-API-v2-sample-code

Sample code for the Twitter API v2 endpoints
https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api
Apache License 2.0
2.65k stars 984 forks source link

Add C# examples #70

Open JannemanDev opened 2 years ago

JannemanDev commented 2 years ago

Would be great if there would be examples in C#.

andypiper commented 2 years ago

We agree! Happy to consider contributions, here.

JannemanDev commented 2 years ago

Well after a day struggling I managed to get it working and like always it was pretty simple :)

using (var client = new WebClient())
{
    client.Headers[HttpRequestHeader.Authorization] = $"Bearer {settings.Twitter.BearerToken}";
    client.OpenReadCompleted += (sender, e) =>
    {
        using (var reader = new StreamReader(e.Result))
        {
            while (!reader.EndOfStream)
            {
                Console.WriteLine(reader.ReadLine());
            }
        }
    };
    client.OpenReadAsync(new Uri(settings.Twitter.FilteredStreamUrl.AbsoluteUri));
}
mathcodes commented 1 year ago

I'd love to add some C#. I'll see what I can do 👍