Error 403 AJAX request JavaScript (instagram direct message)

Viewed 118

I used a script to send direct message automatically in browser console

I login instagram with browser and go to inspect element and tab console copy this code

function getCookie(cname) {
    let name = cname + "=";
    let decodedCookie = decodeURIComponent(document.cookie);
    let ca = decodedCookie.split(';');
    for(let i = 0; i <ca.length; i++) {
        let c = ca[i];
        while (c.charAt(0) == ' ') {
            c = c.substring(1);
        }
        if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
        }
    }
    return "";
}
var deviceID = '89765456789032222';

var user = 192417402;
var formData = new FormData();

formData.append("csrftoken", getCookie('csrftoken'));
formData.append("device_id", "android-"+deviceID); 
formData.append("_uuid", Date.now()); 
formData.append("recipient_users", '[["' + user + '"]]'); // user id can be found on https://www.instagram.com/username/?__a=1
formData.append("client_context",  Date.now()); 
formData.append("text", 'aaaaaaaa'); 

var xhr = new XMLHttpRequest();
xhr.open("POST", "https://i.instagram.com/api/v1/direct_v2/threads/broadcast/text/");
xhr.withCredentials = true;
xhr.send(formData);

It return 403 error to me how to fix it

1 Answers

I don't know the cause of the problem, but you can use the direct message of instagram private api once to prevent 403 from appearing.

Related