1
2
3
4
5
6
7
8
9
10
11
12
13
import { fetch } from "https://esm.town/v/std/fetch";
import { normalizeURL } from "https://esm.town/v/stevekrouse/normalizeURL?v=3";
export async function fetchTweet(url) {
const tweetId = url.match(/(\d{19})/)[1];
const tweetUrl =
`https://cdn.syndication.twimg.com/tweet-result?id=${tweetId}&lang=en`;
const res = await fetch(normalizeURL(tweetUrl), {
redirect: "follow",
});
const tweetData = await res.json();
return tweetData;
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
1
jdan avatar

Clever!

v35
October 23, 2023