TwitterNetCore 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package TwitterNetCore --version 1.0.2                
NuGet\Install-Package TwitterNetCore -Version 1.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TwitterNetCore" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TwitterNetCore --version 1.0.2                
#r "nuget: TwitterNetCore, 1.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TwitterNetCore as a Cake Addin
#addin nuget:?package=TwitterNetCore&version=1.0.2

// Install TwitterNetCore as a Cake Tool
#tool nuget:?package=TwitterNetCore&version=1.0.2                

TwitterNetCore

Description Link
Build Deploy to NuGet
Nuget Nuget

About

Easy to use Twitter API .NET SDK. There are currently a few endpoints still not mapped but will be eventually when I get more time. Feel free to contribute.

Usage

Twitter API documentation https://developer.twitter.com/en/docs/twitter-api

Authentication documentation https://developer.twitter.com/en/docs/authentication/oauth-2-0/authorization-code

Authentication flow that automatically open a web browser to authenticate the user

var authenticationClient = new AuthenticationClient()
{
    ClientId = "<CLIENT_ID>",
    Scopes = "<SCOPES>",
    RedirectUri = "<REDIRECT_URI>",
    // Listening port need to match the redirect uri. 
    // If the redirect uri is http://localhost:5000/ then listening port is 5000
    ListeningPort = <LISTENING_PORT>
};

authenticationClient.GetAuthorizationUrl();
await authenticationClient.GetAuthorizationCode(15);
var tokenObject = await authenticationClient.GetAccessTokenViaAuthorizationCode();

var twitterClient = new TwitterClient
{
    AccessToken = tokenObject.access_token
};

Manual authentication flow

var authenticationClient = new AuthenticationClient()
{
    ClientId = "<CLIENT_ID>",
    RedirectUri = "<REDIRECT_URI>",
    Scopes = "<SCOPES>"
};

var url = authenticationClient.GetAuthorizationUrl();

// PASTE THE URL IN A BROWSER AND AUTHENTICATE TO GENERATE AUTHORIZATION CODE

var tokenObject = await authenticationClient.GetAccessTokenViaAuthorizationCode(<AUTHORIZATION_CODE>);

var twitterClient = new TwitterClient
{
    AccessToken = tokenObject.access_token
};

Post a tweet

var body = new
{
    text = "Hello world!"
};

var response = await twitterClient.CreateTweet(body);

Get a single tweet

var response = await twitterClient.GetTweet("<TWEET_ID>");

Console.WriteLine(response.data.text);

Pass a QueryFields object to any Get method to define query parameters

var getTweetQueryFields = new QueryFields
{
    TweetFields = "attachments,author_id,context_annotations,conversation_id,created_at,entities,geo",
    Expansions = "attachments.poll_ids,attachments.media_keys,author_id,geo.place_id,in_reply_to_user_id",
    MediaFields = "duration_ms,height,media_key,preview_image_url,public_metrics,type,url,width",
    PlaceFields = "contained_within,country,country_code,full_name,geo,id,name,place_type",
    PollFields = "duration_minutes,end_datetime,id,options,voting_status",
    UserFields = "created_at,description,id,location,name,pinned_tweet_id,profile_image_url,url,username,verified"
};

Current methods

  • GetTweet
  • GetTweets
  • CreateTweet
  • DeleteTweet
  • GetUserById
  • GetUserByUsername
  • GetUsersById
  • GetUsersByUsername
  • GetUserFollowers
  • GetUserFollowings
  • FollowUser
  • UnfollowUser
  • BlockUser
  • UnblockUser
  • GetBlockedUsers
  • GetList
  • GetUserLists
  • CreateList
  • UpdateList
  • DeleteList
  • GetListTweets
  • AddListMember
  • RemoveListMember
  • GetListMembers
  • GetUserListMemberships
  • FollowList
  • UnfollowList
  • GetListFollowers
  • GetUserFollowedLists
  • PinList
  • UnpinList
  • GetUserPinnedLists
  • MuteUser
  • UnmuteUser
  • GetUserMutes
  • GetTweetQuoteTweets
  • HideReply
  • UnhideReply
  • LikeTweet
  • UnlikeTweet
  • GetUserLikedTweets
  • GetUsersLikingTweet
  • RetweetTweet
  • UndoRetweet
  • GetRetweetedByUsers
  • GetDirectMessagesByConversation
  • GetDirectMessagesByConversationIncludingExactlyTwoParticipants
  • GetDirectMessagesByUser

Twitter API Postman https://www.postman.com/twitter/workspace/twitter-s-public-workspace/collection/9956214-784efcda-ed4c-4491-a4c0-a26470a67400?ctx=documentation

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.5 365 2/25/2023
1.0.4 234 2/23/2023
1.0.3 235 2/23/2023
1.0.2 247 2/23/2023
1.0.0 234 2/23/2023