{"id":13729206,"url":"https://github.com/Xwilarg/TwitterSharp","last_synced_at":"2025-05-08T01:31:53.607Z","repository":{"id":42393646,"uuid":"364050030","full_name":"Xwilarg/TwitterSharp","owner":"Xwilarg","description":"C# wrapper around Twitter API V2","archived":false,"fork":false,"pushed_at":"2023-09-27T09:26:08.000Z","size":256,"stargazers_count":68,"open_issues_count":9,"forks_count":12,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-25T04:48:27.529Z","etag":null,"topics":["tweets","twitter","twitter-api","twitter-api-v2","twitter-streaming-api","wrapper"],"latest_commit_sha":null,"homepage":"https://twittersharp.zirk.eu","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Xwilarg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-05-03T20:16:33.000Z","updated_at":"2025-03-31T14:08:09.000Z","dependencies_parsed_at":"2024-01-06T13:08:21.890Z","dependency_job_id":"5af21862-4050-44be-beb1-a9cec9e98994","html_url":"https://github.com/Xwilarg/TwitterSharp","commit_stats":{"total_commits":167,"total_committers":9,"mean_commits":"18.555555555555557","dds":0.4011976047904192,"last_synced_commit":"029d6846c6ceb48658f7c3308663449a11f91add"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xwilarg%2FTwitterSharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xwilarg%2FTwitterSharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xwilarg%2FTwitterSharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xwilarg%2FTwitterSharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Xwilarg","download_url":"https://codeload.github.com/Xwilarg/TwitterSharp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252981573,"owners_count":21835453,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["tweets","twitter","twitter-api","twitter-api-v2","twitter-streaming-api","wrapper"],"created_at":"2024-08-03T02:00:56.802Z","updated_at":"2025-05-08T01:31:53.325Z","avatar_url":"https://github.com/Xwilarg.png","language":"C#","funding_links":[],"categories":["Libraries"],"sub_categories":["C# / .NET"],"readme":"# TwitterSharp\nC# wrapper around Twitter API V2\n\n| CI | Code Quality | Coverage |\n| -- | ------------ | -------- |\n| [![.NET](https://github.com/Xwilarg/TwitterSharp/actions/workflows/ci.yml/badge.svg)](https://github.com/Xwilarg/TwitterSharp/actions/workflows/ci.yml) | [![Codacy Badge](https://app.codacy.com/project/badge/Grade/726fd5c6287644d48807fcf03a18d868)](https://www.codacy.com/gh/Xwilarg/TwitterSharp/dashboard?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=Xwilarg/TwitterSharp\u0026amp;utm_campaign=Badge_Grade) | [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/726fd5c6287644d48807fcf03a18d868)](https://www.codacy.com/gh/Xwilarg/TwitterSharp/dashboard?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=Xwilarg/TwitterSharp\u0026utm_campaign=Badge_Coverage) |\n\n## Download\n\nThe package is available on [NuGet](https://www.nuget.org/packages/TwitterSharp/)\n```powershell\nInstall-Package TwitterSharp\n```\n\n## Documentation\nhttps://twittersharp.zirk.eu\n\n## How does it works?\n\nTo begin with, please go to the [Twitter Developer Portal](https://developer.twitter.com/) and create a new application\\\nThen you must instantiate a new client:\n```cs\nvar client = new TwitterSharp.Client.TwitterClient(bearerToken);\n```\nFrom there you can access various methods to access tweets and users, however please make note that a basic request only includes:\n - For tweets: its ID and content\n - For users: its ID, name and username\n\nTo solve that, most function take an array of UserOption or TweetOption, make sure to add what you need there!\n\nNeed more help? You can use the examples below, if you're still lost feel free to open an issue or a discussion!\n\n## Examples\n### Get a tweet from its ID\n```cs\nvar client = new TwitterSharp.Client.TwitterClient(bearerToken);\nvar answer = await client.GetTweetAsync(\"1389189291582967809\");\nConsole.WriteLine(answer.Text); // たのしみ！！\\uD83D\\uDC93 https://t.co/DgBYVYr9lN\n```\n\n### Get an user from its username\n```cs\nvar client = new TwitterSharp.Client.TwitterClient(bearerToken);\nvar answer = await client.GetUserAsync(\"theindra5\");\nConsole.WriteLine(answer.Id); // 1022468464513089536\n```\n\n### Get latest tweets from an user id with the attached medias\n```cs\nvar client = new TwitterSharp.Client.TwitterClient(bearerToken);\n// You can get the id using GetUsersAsync\nvar answer = await client.GetTweetsFromUserIdAsync(\"1109748792721432577\", new TweetSearchOptions\n{\n    TweetOptions = new[] { TweetOption.Attachments },\n    MediaOptions = new[] { MediaOption.Preview_Image_Url }\n});\nfor (int i = 0; i \u003c answer.Length; i++)\n{\n    var tweet = answer[i];\n    Console.WriteLine($\"Tweet n°{i}\");\n    Console.WriteLine(tweet.Text);\n    if (tweet.Attachments?.Media?.Any() ?? false)\n    {\n        Console.WriteLine(\"\\nImages:\");\n        Console.WriteLine(string.Join(\"\\n\", tweet.Attachments.Media.Select(x =\u003e x.Url)));\n    }\n    Console.WriteLine(\"\\n\");\n}\n```\n\n### Get the users that someone follow\n```cs\nvar client = new TwitterClient(Environment.GetEnvironmentVariable(\"TWITTER_TOKEN\"));\n\nvar answer = await client.GetFollowingAsync(\"1433657158067896325\", new UserSearchOptions\n{\n    Limit = 1000\n});\nConsole.WriteLine(string.Join(\"\\n\", answer.Users.Select(u =\u003e u.Username)));\nwhile (answer.NextAsync != null) // We go to the next page if there is one\n{\n    answer = await answer.NextAsync();\n    Console.WriteLine(string.Join(\"\\n\", answer.Users.Select(u =\u003e u.Username)));\n}\n```\n\n### Continuously get all the new tweets from some users\n```cs\nvar client = new TwitterSharp.Client.TwitterClient(bearerToken);\n\n// Subscribe to 5 Twitter accounts\nvar request = new TwitterSharp.Request.StreamRequest(\n    Expression.Author(\"moricalliope\") // using TwitterSharp.Rule;\n        .Or(\n            Expression.Author(\"takanashikiara\"),\n            Expression.Author(\"ninomaeinanis\"),\n            Expression.Author(\"gawrgura\"),\n            Expression.Author(\"watsonameliaEN\")\n        )\n, \"Hololive\");\nawait client.AddTweetStreamAsync(request); // Add them to the stream\n\n// We display all the subscriptions we have\nvar subs = await client.GetInfoTweetStreamAsync();\nConsole.WriteLine(\"Subscriptions: \" + string.Join(\"\\n\", subs.Select(x =\u003e x.Value.ToString())));\n\n// NextTweetStreamAsync will continue to run in background\nTask.Run(async () =\u003e\n{\n    // Take in parameter a callback called for each new tweet\n    // Since we want to get the basic info of the tweet author, we add an empty array of UserOption\n    await client.NextTweetStreamAsync((tweet) =\u003e\n    {\n        Console.WriteLine($\"From {tweet.Author.Name}: {tweet.Text} (Rules: {string.Join(',', tweet.MatchingRules.Select(x =\u003e x.Tag))})\");\n    },\n    new TweetSearchOptions\n    {\n        UserOptions = Array.Empty\u003cUserOption\u003e()\n    });\n});\n\n// Add new high frequent rule after the stream started. No disconnection needed.\nawait client.AddTweetStreamAsync(new TwitterSharp.Request.StreamRequest( Expression.Author(\"Every3Minutes\"), \"Frequent\"));\n```\n\n### Search the expression tree\n```cs\nvar expressionString = \"(@twitterdev OR @twitterapi) -@twitter\";\n// Parse the string into an expression with a typed expression tree\nvar parsedExpression = Expression.Parse(expressionString);\n\nvar mentionsCount = CountExpressionsOfType(parsedExpression, ExpressionType.Mention);\nvar groupsCount = CountExpressionsOfType(parsedExpression, ExpressionType.And) + CountExpressionsOfType(parsedExpression, ExpressionType.Or);;\n\nConsole.WriteLine($\"Found {mentionsCount} mentions and {groupsCount} groups in the expression\"); // Found 3 mentions and 2 groups in the expression\n\n// Helper function to count recursive\nint CountExpressionsOfType(Expression expression, ExpressionType type)\n{\n    var i = expression.Type == type ? 1 : 0;\n\n    if (expression.Expressions != null)\n    {\n        i += expression.Expressions.Sum(exp =\u003e CountExpressionsOfType(exp, type));\n    }\n\n    return i;\n}\n```\n\n## Contributing\n\nIf you want to contribute feel free to open a pull request\\\nYou can also see how the project is going in the [project tab](https://github.com/Xwilarg/TwitterSharp/projects/1)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FXwilarg%2FTwitterSharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FXwilarg%2FTwitterSharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FXwilarg%2FTwitterSharp/lists"}