// Defining import libraries here
import fetch from "node-fetch";
// Define API key here
const CLIENT_ID = "{{CLIENT_ID}}";
const CLIENT_SECRET = "{{CLIENT_SECRET}}";
// Creating a basic auth token using account ID and license key
const authToken = Buffer.from(`${CLIENT_ID}:${CLIENT_SECRET}`).toString(
"base64"
);
const encoded = authToken.toString("base64");
// Define endpoint URL here
const endpointUrl = new URL("https://www.reddit.com/api/v1/access_token");
// Define Header Parameters here
const headerParameters = {
Authorization: `Basic ${encoded}`,
contentType: "application/json",
};
// Define Body Parameters here
const bodyParameters = new URLSearchParams({
grant_type: "refresh_token",
client_id: "qwnrWzLI75jlYuAVN2ptcg",
client_secret: "HDTnQjO10YwPRKr0epzP0BJj92dyEQ",
refresh_token: "{{REFRESH_TOKEN}}",
});
// Setting API call options
const options = {
method: "POST",
headers: headerParameters,
body: bodyParameters,
};
// Function to make API call
async function accessTokenUpdation() {
try {
const response = await fetch(endpointUrl, options);
// Custom function for printing the API response
printResponse(response);
} catch (error) {
// Custom function for printing the error message
printError(error);
}
}
// Calling function to make API call
accessTokenUpdation();