Pinterest Access token generation

For generating the access token we need to execute the below request 

curl -X POST https://api.pinterest.com/v5/oauth/token
--header 'Authorization: Basic {base64 encoded string made of client_id:client_secret}'
--header 'Content-Type: application/x-www-form-urlencoded'
--data-urlencode 'grant_type=authorization_code'
--data-urlencode 'code={YOUR_CODE}'
--data-urlencode 'redirect_uri=http://localhost/'

Java Script XHR code

// WARNING: For POST requests, body is set to null by browsers.
var data = "grant_type=authorization_code&code=wjcnjhdbcnweghnjwdhceufhcuhhujfh&redirect_uri=https%3A%2F%2Fwww.qwerty.com";

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "https://api.pinterest.com/v5/oauth/token");
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Authorization", "Basic Mhefgbefgwhhbhjhjdjuwhyyhdedbwdcwef");
// WARNING: Cookies will be stripped away by the browser before sending the request.
xhr.setRequestHeader("Cookie", "_auth=0; _pinterest_sess=TW3ed23rderfwergfterhgytrgvfvwdfcwedcewrfewrfweerfgtrg==");

xhr.send(data);

Leave a comment

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