Skip to content

Latest commit

 

History

History
100 lines (71 loc) · 2.15 KB

README.md

File metadata and controls

100 lines (71 loc) · 2.15 KB

Twitter API v2 (early access) client for Deno

https://developer.twitter.com/en/docs/twitter-api/early-access

Tweets

Lookup

Retrieve a single Tweet with an ID

import { getTweet } from "https://deno.land/x/twitter_api_client/api_v2/tweets/lookup.ts";

const bearerToken = ""; // bearerToken

const res = await getTweet(bearerToken, "1067094924124872705" /*,option*/);

Retrieve multiple Tweets with a list of IDs

import { getTweets } from "https://deno.land/x/twitter_api_client/api_v2/tweets/lookup.ts";

const bearerToken = ""; // bearerToken

const res = await getTweets(bearerToken, {
  ids: ["1261326399320715264", "1278347468690915330"],
  /* option */
});

Filtered Stream

Add or delete rules from your stream

import { changeRules } from "https://deno.land/x/twitter_api_client/api_v2/tweets/filtered_stream.ts";

const bearerToken = ""; // bearerToken

// Either "add" or "delete"
const res = await changeRules(bearerToken, {
  add: [
    { value: "cat has:media", tag: "cats with media" },
    { value: "cats has:media -grumpy", tag: "happy cats with media" },
    { value: "meme", tag: "funny things" },
    { value: "meme has:images" },
  ],
  // delete: {
  //   ids: [
  //     "1165037377523306498",
  //     "1165037377523306499",
  //   ],
  // },
});

/*
At the time of "dry_run"

await changeRules("bearerToken","rules",true);
*/

Retrieve your stream's rules

import { getRules } from "https://deno.land/x/twitter_api_client/api_v2/tweets/filtered_stream.ts";

const bearerToken = ""; // bearerToken

const res = await getRules(bearerToken);

Connect to the stream

import {
  connectStream,
  StreamTweet,
} from "https://deno.land/x/twitter_api_client/api_v2/tweets/filtered_stream.ts";

const bearerToken = ""; // bearerToken

async function callback(a: StreamTweet) {
  // any processing
}

// none option
const disconnect = connectStream(bearerToken, callback);

// with option
connectStream(bearerToken, callback, {
  expansions: {
    author_id: true,
  },
});

// Disconnect Stream after 10sec.
setTimeout(() => disconnect(), 10 * 1000);