Pinterest-Token Generation Using Refresh Token

Following function can be used for generating Pinterest token with the help of a refresh token.

genereateTokenUsingRefreshtoken() {
// WARNING: For POST requests, body is set to null by browsers.
var refreshToken = 'pinr.efef3wr2r==';
var data = "grant_type=refresh_token&refresh_token=" + encodeURIComponent(refreshToken) + "&scope%3Dboards=read&refresh_on=true";
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
return new Promise(function (resolve, reject) {
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
							console.log('genereateTokenUsingRefreshtoken response', this.responseText);
var responseObj = JSON.parse(this.responseText);
var accessToken = responseObj.access_token;
Cookie.set("GeneratedToken", accessToken, { expires: null });
resolve(accessToken);
						}
					});
xhr.open("POST", "https://api.pinterest.com/v5/oauth/token");
xhr.setRequestHeader("Authorization", "Basic MghDgzNTg0");
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
// WARNING: Cookies will be stripped away by the browser before sending the request.
xhr.setRequestHeader("Cookie", "_auth=0; _pinterest_sess=TdsPQ==; _ir=0");

xhr.send(data);

});

			},

Leave a comment

Your email address will not be published. Required fields are marked *