{"id":8294153,"url":"https://github.com/xdevplatform/twitter-api-typescript-sdk","last_synced_at":"2025-12-15T20:18:41.078Z","repository":{"id":36975881,"uuid":"370910066","full_name":"xdevplatform/twitter-api-typescript-sdk","owner":"xdevplatform","description":"A TypeScript SDK for the Twitter API","archived":false,"fork":false,"pushed_at":"2024-01-12T16:57:28.000Z","size":259,"stargazers_count":970,"open_issues_count":45,"forks_count":100,"subscribers_count":20,"default_branch":"main","last_synced_at":"2025-05-15T09:02:45.775Z","etag":null,"topics":["javascript","nodejs","twitter","twitter-api","twitter-api-v2","typescript"],"latest_commit_sha":null,"homepage":"https://developer.twitter.com/en/docs/twitter-api","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xdevplatform.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-05-26T04:54:33.000Z","updated_at":"2025-05-14T01:14:31.000Z","dependencies_parsed_at":"2024-01-06T13:08:27.458Z","dependency_job_id":"fe6d4130-a533-469d-994e-d4b14e21284c","html_url":"https://github.com/xdevplatform/twitter-api-typescript-sdk","commit_stats":{"total_commits":40,"total_committers":6,"mean_commits":6.666666666666667,"dds":"0.19999999999999996","last_synced_commit":"0d12a20a76d6dd9c346decf9cc80bc611975d43f"},"previous_names":["xdevplatform/twitter-api-typescript-sdk"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xdevplatform%2Ftwitter-api-typescript-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xdevplatform%2Ftwitter-api-typescript-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xdevplatform%2Ftwitter-api-typescript-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xdevplatform%2Ftwitter-api-typescript-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xdevplatform","download_url":"https://codeload.github.com/xdevplatform/twitter-api-typescript-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254544146,"owners_count":22088807,"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":["javascript","nodejs","twitter","twitter-api","twitter-api-v2","typescript"],"created_at":"2024-04-20T22:03:04.760Z","updated_at":"2025-12-15T20:18:40.988Z","avatar_url":"https://github.com/xdevplatform.png","language":"TypeScript","readme":"# Twitter API SDK for TypeScript\n\n## Introduction\n\nA TypeScript SDK for the Twitter API. This library is built with TypeScript developers in mind, but it also works with JavaScript.\n\n**Note: This SDK is in beta and is not ready for production**\n\nYou can find examples of using the client in the [examples/](examples/) directory\n\n**Note: Only Twitter API V2 is supported**\n\n### Features\n\n- Full type information for requests and responses\n- OAuth2 support\n- Supports Node.js 14+. **Doesn't work in browser environments due to the Twitter API not supporting CORS**\n\n## Installing\n\n```\nnpm install twitter-api-sdk\n```\n\n## Client\n\nTo setup the client we will authenticate with a bearer-token as follows\n\n```typescript\nimport { Client } from \"twitter-api-sdk\";\n\nconst client = new Client(\"MY-BEARER-TOKEN\");\n```\n\nFor more information about authentication [go here](#authentication)\n\n## Examples\n\n### Consuming a Stream\n\n```typescript\nimport { Client } from \"twitter-api-sdk\";\n\nconst client = new Client(process.env.BEARER_TOKEN);\n\nasync function main() {\n  const stream = client.tweets.sampleStream({\n    \"tweet.fields\": [\"author_id\"],\n  });\n  for await (const tweet of stream) {\n    console.log(tweet.data?.author_id);\n  }\n}\n\nmain();\n```\n\n### Getting a Tweet\n\n```typescript\nimport { Client } from \"twitter-api-sdk\";\n\nconst client = new Client(process.env.BEARER_TOKEN);\n\nasync function main() {\n  const tweet = await client.tweets.findTweetById(\"20\");\n  console.log(tweet.data.text);\n}\n\nmain();\n```\n\n## Streaming\n\nFor endpoints that return a stream you get sent back an Async Generator which you can iterate over:\n\n```typescript\nconst stream = client.tweets.sampleStream();\n\nfor await (const tweet of stream) {\n  console.log(tweet.data.text);\n}\n```\n\n## Pagination\n\nFor endpoints that have pagination you can\n\n```typescript\nconst followers = client.users.usersIdFollowers(\"20\");\n\nfor await (const page of followers) {\n  console.log(page.data);\n}\n\n// This also works\nconst followers = await client.users.usersIdFollowers(\"20\");\nconsole.log(followers.data);\n```\n\n## Authentication\n\nThis library supports App-only Bearer Token and OAuth 2.0\n\nYou can see various examples on how to use the authentication in [examples/](examples/)\n\n## Getting Started\n\nMake sure you turn on OAuth2 in your apps user authentication settings, and set the type of app to be either a confidential client or a public client.\n\n### Creating a Public Auth Client\n\n```typescript\nconst authClient = new auth.OAuth2User({\n  client_id: process.env.CLIENT_ID,\n  callback: \"http://127.0.0.1:3000/callback\",\n  scopes: [\"tweet.read\", \"users.read\", \"offline.access\"],\n});\n\nconst client = new Client(authClient);\n```\n\n### Creating a Confidential Auth Client\n```typescript\nconst authClient = new auth.OAuth2User({\n  client_id: process.env.CLIENT_ID,\n  client_secret: process.env.CLIENT_SECRET,\n  callback: \"http://127.0.0.1:3000/callback\",\n  scopes: [\"tweet.read\", \"users.read\", \"offline.access\"],\n});\n\nconst client = new Client(authClient);\n```\n\n\n### Generating an Authentication URL\n\n```typescript\nconst authUrl = authClient.generateAuthURL({\n  code_challenge_method: \"s256\",\n});\n```\n\n### Requesting an Access Token\n\nOnce the user has approved the OAuth flow, you will receive a `code` query parameter at the callback URL you specified.\n\n```typescript\nawait authClient.requestAccessToken(code);\n```\n\n### Revoking an Access Token\n\n```typescript\nconst response = await authClient.revokeAccessToken();\n```\n\n## Contributing\n\nNote this is only for developers who want to contribute code to the SDK\n\n\n### Clone the Repository\n\n```\ngit clone https://github.com/twitterdev/twitter-api-typescript-sdk\n```\n\n### Running the Generation Script\n\nGenerating the SDK with the [latest OpenAPI spec](https://api.twitter.com/2/openapi.json). The version is any valid [SemVer](https://semver.org/) version\n\n```\nyarn generate 1.0.0\n```\n\nGenerating the SDK with a local OpenAPI specification file.\n\n```\nyarn generate 1.0.0 --specFile ~/path/to/file/openapi.json\n```\n\nThe files generated are put in the [src/gen](src/gen) directory, these files are not edited manually.\n\n### Building\n\n```\nyarn build\n```\n\n### Testing\n\n```\nyarn test\n```\n\n","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxdevplatform%2Ftwitter-api-typescript-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxdevplatform%2Ftwitter-api-typescript-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxdevplatform%2Ftwitter-api-typescript-sdk/lists"}