Public
HTTP (deprecated)
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Readme

Twitter API Wrapper

So that I can share my $100 / month key with a couple Val Town Pro users. Contact me (or comment on this val) if you'd like to get in on the action.

Usage

undefined
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { ratelimit } from "https://esm.town/v/rlimit/ratelimit?v=39";
import { twitterJSON } from "https://esm.town/v/stevekrouse/twitterJSON";
export default async function(req: Request): Promise<Response> {
if (req.headers.get("authorization") !== "Bearer " + Deno.env.get("boozedog"))
return Response.json("Unauthorized", { status: 401 });
const limit = await ratelimit("5/1h", "twitter-rl");
console.log(limit);
if (!limit.ok) {
return Response.json("Rate limit reached", { status: 429 });
}
let url = new URL(req.url);
console.log("https://api.twitter.com" + url.pathname + url.search);
return Response.json(
await twitterJSON({
url: "https://api.twitter.com/" + url.pathname + url.search,
bearerToken: Deno.env.get("twitter"),
}),
);
}
stevekrouse-twitterwrapper.web.val.run
December 22, 2023