简体   繁体   中英

Why am I getting an error 403 while sending a post request to Instagram?

I want to unfollow specific user on instagram by using a request to endpoint, for which I have used fiddler to find. But I'm getting an 403 error and nothing happends. I'm a newbie at this.

Here is the code:

var http = new XMLHttpRequest();
var url = 'https://www.instagram.com/web/friendships/8752655712/unfollow/';
var params = 'orem=ipsum&name=binny';
http.open('POST', url, true);

//Send the proper header information along with the request
http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');

http.onreadystatechange = function() {//Call a function when the state changes.
    if(http.readyState == 4 && http.status == 200) {
        alert(http.responseText);
    }
}
http.send(params);

Is there any technical aspect that I'm missing?

EDIT 1: I'm sending it from chrome console while logged to my instagram account.

Yes you are missing few things.

Authentication

When you're browsing Instagram as usual, browser will add headers to each request. What's more important that headers contain cookies and origin. By executing the code you listed headers (or any other authentication data) is not added.

Other security checks

I guess Instagram checks origin of received requests. It may not be possible to execute it this way - ie. manually executing JS code.

Possible solution - use API provided by Instagram. For more details please refer to documentation: https://www.instagram.com/developer/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM