//native
type Pinterest = {
token: string;
};
/**
* Generate OAuth access token
* Generate an OAuth access token by using an authorization code or a refresh token.
*/
export async function main(
auth: Pinterest,
body: {
grant_type: "authorization_code" | "refresh_token" | "client_credentials";
},
) {
const url = new URL(`https://api.pinterest.com/v5/oauth/token`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Authorization: "Bearer " + auth.token,
},
body: new URLSearchParams(body as Record<string, string>),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 536 days ago