twitter-api-v2
Advanced tools
Comparing version 0.2.0 to 0.2.1
{ | ||
"name": "twitter-api-v2", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Twitter api v1 and v2 client for node", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
@@ -7,0 +8,0 @@ "build": "tsc", |
# Twitter API V2 | ||
WIP | ||
Twitter api V1 and V2 client for node | ||
Twitter api v2 (and v1 in the future) client for node | ||
## How to use | ||
```typescript | ||
import TwitterApi, { TwitterErrors } from 'twitter-api-v2'; | ||
// bearer token auth (with V2) | ||
const twitterClient = new TwitterApi('<YOUR_APP_USER_TOKEN>'); | ||
// token auth | ||
const twitterClient = new TwitterApi({ | ||
appKey: '<YOUR-TWITTER-APP-TOKEN>', | ||
appSecret: '<YOUR-TWITTER-APP-SECERT>', | ||
accessToken: '<YOUR-TWITTER-APP-TOKEN>', | ||
accessSecret: '<YOUR-TWITTER-APP-SECERT>', | ||
}); | ||
// link auth | ||
const twitterClient = new TwitterApi({ | ||
appKey: '<YOUR-TWITTER-APP-TOKEN>', | ||
appSecret: '<YOUR-TWITTER-APP-SECERT>', | ||
}); | ||
const authLink = await twitterClient.generateAuthLink(); | ||
// ... redirected to https://website.com?oauth_token=XXX&oauth_verifier=XXX | ||
const { usertoken, userSecret } = twitterClient.login('<THE_OAUTH_VERIFIER>'); | ||
// Tell typescript it's a readonly app | ||
const twitterClient = new TwitterApi(xxx).readOnly; | ||
// Manually call the API | ||
const tweets = await twitterClient.v2.get('tweets/search/recent', {query: 'nodeJS', max_results: '100'}); | ||
const tweets = await twitterClient.v1.tweet('Hello, this is a test.'), | ||
const tweets = await twitterClient.v1.uploadMedia(await fs.promises.readFile(path), { type: 'jpg' }) | ||
const tweets = await twitterClient.get('https://api.twitter.com/2/tweets/search/recent?query=nodeJS&max_results=100'); | ||
``` | ||
## Why? | ||
@@ -36,18 +70,4 @@ | ||
// bearer token auth (with V2) | ||
const twitterClient = new TwitterApi('<YOUR_APP_USER_TOKEN>'); | ||
const twitterClient = new TwitterApi(tokens); | ||
// token auth | ||
const twitterClient = new TwitterApi({ | ||
appKey: '<YOUR-TWITTER-APP-TOKEN>', | ||
appSecret: '<YOUR-TWITTER-APP-SECERT>', | ||
accesToken: '<YOUR-TWITTER-APP-TOKEN>', | ||
accessSecret: '<YOUR-TWITTER-APP-SECERT>', | ||
}); | ||
// link auth | ||
const twitterClient = new TwitterApi({ | ||
appKey: '<YOUR-TWITTER-APP-TOKEN>', | ||
appSecret: '<YOUR-TWITTER-APP-SECERT>', | ||
}); | ||
const authLink = await twitterClient.generateAuthLink(); | ||
@@ -57,12 +77,5 @@ // ... redirected to https://website.com?oauth_token=XXX&oauth_verifier=XXX | ||
// Tell typescript it's a readonly app | ||
const twitterClient = new TwitterApi(xxx).readOnly; | ||
// Search for tweets | ||
const tweets = await twitterClient.tweets.search('nodeJS', { max_results: 100 }); | ||
// Or do it your way (however, with no result typed) | ||
const tweets = await twitterClient.v2.get('tweets/search/recent', {query: 'nodeJS', max_results: '100'}); | ||
const tweets = await twitterClient.get('https://api.twitter.com/2/tweets/search/recent?query=nodeJS&max_results=100'); | ||
// Auto-paginate | ||
@@ -69,0 +82,0 @@ // (also checks if rate limits will be enough after the first request) |
@@ -13,3 +13,3 @@ { | ||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ | ||
// "declaration": true, /* Generates corresponding '.d.ts' file. */ | ||
"declaration": true, /* Generates corresponding '.d.ts' file. */ | ||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ | ||
@@ -16,0 +16,0 @@ // "sourceMap": true, /* Generates corresponding '.map' file. */ |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
67442
24
93
0