Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { basicAuthorization } from "https://esm.town/v/stevekrouse/basicAuthorization";
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
export async function refreshTwitterToken(
{ refresh_token, client_id, client_secret }: {
refresh_token: string;
client_id: string;
client_secret: string;
},
) {
const url = "https://api.twitter.com/2/oauth2/token";
const body = new URLSearchParams({
grant_type: "refresh_token",
refresh_token,
client_id,
});
return fetchJSON(url, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
...basicAuthorization(client_id, client_secret),
},
body: body.toString(),
});
}
November 7, 2023