Fetch
var myHeaders = new Headers();
myHeaders.append("Cookie", "csrftoken=lsDzlik5lO5y33cshMhIgMYIOzmh3CLv; rur=FTW");
var formdata = new FormData();
formdata.append("client_id", "990602627938098");
formdata.append("client_secret", "eb8c7...");
formdata.append("grant_type", "authorization_code");
formdata.append("redirect_uri", "https://socialsizzle.herokuapp.com/auth/");
formdata.append("code", "AQBx-hBsH3...");
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: formdata,
redirect: 'follow'
};
fetch("https://api.instagram.com/oauth/access_token", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
XHR
var data = new FormData();
data.append("client_id", "990602627938098");
data.append("client_secret", "eb8c7...");
data.append("grant_type", "authorization_code");
data.append("redirect_uri", "https://socialsizzle.herokuapp.com/auth/");
data.append("code", "AQBx-hBsH3...");
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://api.instagram.com/oauth/access_token");
xhr.setRequestHeader("Cookie", "csrftoken=lsDzlik5lO5y33cshMhIgMYIOzmh3CLv; rur=FTW");
xhr.send(data);
jQuery
var form = new FormData();
form.append("client_id", "990602627938098");
form.append("client_secret", "eb8c7...");
form.append("grant_type", "authorization_code");
form.append("redirect_uri", "https://socialsizzle.herokuapp.com/auth/");
form.append("code", "AQBx-hBsH3...");
var settings = {
"url": "https://api.instagram.com/oauth/access_token",
"method": "POST",
"timeout": 0,
"headers": {
"Cookie": "csrftoken=lsDzlik5lO5y33cshMhIgMYIOzmh3CLv; rur=FTW"
},
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};
$.ajax(settings).done(function (response) {
console.log(response);
});