Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@kochie/twitter-api-sdk
Advanced tools
With the space mans acquisition of Twitter I think there's a better chance of finding life on Mars than seeing this API updated. So let's keep it alive as a community.
A TypeScript SDK for the Twitter API. This library is built with TypeScript developers in mind, but it also works with JavaScript.
Note: This SDK is in beta and is not ready for production
You can find examples of using the client in the examples/ directory
Note: Only Twitter API V2 is supported
npm install twitter-api-sdk
To setup the client we will authenticate with a bearer-token as follows
import { Client } from "twitter-api-sdk";
const client = new Client("MY-BEARER-TOKEN");
For more information about authentication go here
import { Client } from "twitter-api-sdk";
const client = new Client(process.env.BEARER_TOKEN);
async function main() {
const stream = client.tweets.sampleStream({
"tweet.fields": ["author_id"],
});
for await (const tweet of stream) {
console.log(tweet.data?.author_id);
}
}
main();
import { Client } from "twitter-api-sdk";
const client = new Client(process.env.BEARER_TOKEN);
async function main() {
const tweet = await client.tweets.findTweetById("20");
console.log(tweet.data.text);
}
main();
For endpoints that return a stream you get sent back an Async Generator which you can iterate over:
const stream = client.tweets.sampleStream();
for await (const tweet of stream) {
console.log(tweet.data.text);
}
For endpoints that have pagination you can
const followers = client.users.usersIdFollowers("20");
for await (const page of followers) {
console.log(page.data);
}
// This also works
const followers = await client.users.usersIdFollowers("20");
console.log(followers.data);
This library supports App-only Bearer Token and OAuth 2.0
You can see various examples on how to use the authentication in examples/
Make 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.
const authClient = new auth.OAuth2User({
client_id: process.env.CLIENT_ID,
callback: "http://127.0.0.1:3000/callback",
scopes: ["tweet.read", "users.read", "offline.access"],
});
const client = new Client(authClient);
const authClient = new auth.OAuth2User({
client_id: process.env.CLIENT_ID,
client_secret: process.env.CLIENT_SECRET,
callback: "http://127.0.0.1:3000/callback",
scopes: ["tweet.read", "users.read", "offline.access"],
});
const client = new Client(authClient);
const authUrl = authClient.generateAuthURL({
code_challenge_method: "s256",
});
Once the user has approved the OAuth flow, you will receive a code
query parameter at the callback URL you specified.
await authClient.requestAccessToken(code);
const response = await authClient.revokeAccessToken();
Note this is only for developers who want to contribute code to the SDK
git clone https://github.com/twitterdev/twitter-api-typescript-sdk
Generating the SDK with the latest OpenAPI spec. The version is any valid SemVer version
yarn generate 1.0.0
Generating the SDK with a local OpenAPI specification file.
yarn generate 1.0.0 --specFile ~/path/to/file/openapi.json
The files generated are put in the src/gen directory, these files are not edited manually.
yarn build
yarn test
FAQs
A TypeScript SDK for the Twitter API
The npm package @kochie/twitter-api-sdk receives a total of 1 weekly downloads. As such, @kochie/twitter-api-sdk popularity was classified as not popular.
We found that @kochie/twitter-api-sdk demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.