开发者

How to Delete Facebook Messages via Facebook API?

开发者 https://www.devze.com 2023-04-09 19:30 出处:网络
Is there a way to retrieve all Facebook Message ids with the read mailbox permission and then delete them all one by one? Everyone is crying about how it\'s difficult to delete your chat/message histo

Is there a way to retrieve all Facebook Message ids with the read mailbox permission and then delete them all one by one? Everyone is crying about how it's difficult to delete your chat/message history. I wondered if there was an easy way to write an app to do this.

Fa开发者_如何学编程cebook API - Message


Normally you would issue an HTTP DELETE call to https://graph.facebook.com/messageID?access_token=... But it appears that this is an API call that either require special whitelisting from Facebook or isn't currently supported because it does not work right now and returns "Unsupported delete request."


Install https://chrome.google.com/webstore/detail/jquerify/gbmifchmngifmadobkcpijhhldeeelkc

Open the facebook using https://mbasic.facebook.com/messages/?_rdr

Enable jQuery using jQueryify extension you installed. Then go to your chrome developer tools> sources > snippet and create a new snippet and paste the following code and run it.

// Code snippet for facebook messages removing:

var WHITELISTED_USERS_X = [];
function removeElement(elementId) {
    // Removes an element from the document
    var element = document.getElementById(elementId);
    if (element) {
        element.parentNode.removeChild(element);
    }
}

function addElement(parentId, elementTag, elementId, html) {
    // Adds an element to the document
    //     removeElement
    removeElement(elementId);
    var p = document.getElementById(parentId);
    var newElement = document.createElement(elementTag);
    newElement.setAttribute('id', elementId);
    newElement.innerHTML = html;
    if (p) {
        p.appendChild(newElement);
    } else {
        var body = document.getElementsByTagName("body")[0]
        body.appendChild(newElement);
    }

}
addElement("body", "div", "123x", "hello World23");
console.log(`getOlderMessagesLink()`);
console.log(getOlderMessagesLink());
var aLinks = document.querySelectorAll('h3 a'), i;

for (i = 0; i < aLinks.length; ++i) {
    let currentLink = aLinks[i];
    currentLink.style.color = currentLink.style.color == "black" ? "red" : "green";

    $.get( currentLink.href, function( data ) {

    getPayload1(currentLink.href).then(payLoad=>{
    let abLink = currentLink.href;
    let deleteApiLink = abLink.split('?').pop().split('&');
    deleteApiLink.splice(1 , 0, `tids=${deleteApiLink[0].split('=').pop()}`)
    deleteApiLink = deleteApiLink.join("&").split("#").shift();    
    const apiLink = `https://mbasic.facebook.com/messages/action_redirect?` + deleteApiLink;

    $.post(apiLink, payLoad ).done(function( data ) {
    let mydeletehref = findInParsed(data, "a:contains('Delete')");
    const username = currentLink.innerText;
    const deleteLink = mydeletehref.href;
    if(WHITELISTED_USERS_X.indexOf(username) == -1){
        // console.log(`${username}: ${deleteLink}`);
        insertDeleteLinkInUser(username, deleteLink);
    }

  });


    });
      })

}
function getPayload1(link){
    return new Promise(resp=>{
        $.get(link, function( html1 ) {
        let fbDtsg = findInParsed(html1, "input[name='fb_dtsg']");
        let jazoest = findInParsed(html1, "input[name='jazoest']");
        resp ({
            "fb_dtsg": fbDtsg.value,
            "jazoest": jazoest.value,
            "delete": "Delete"
        })
    }); 
    })
}
function findInParsed(html, selector){
    return $(selector, html).get(0) || $(html).filter(selector).get(0);
}
function getOlderMessagesLink(html = false){
    if(html){
        return $("#see_older_threads").find("a").get(0).href;
    }
    let selector = "#see_older_threads";
    return $(selector, html).find("a").get(0).href || $(html).filter(selector).find("a").get(0).href;
}
function insertDeleteLinkInUser(username, link){
    $("a:contains('" + username + "')").parent().parent().parent().prepend('<a href="' + link + '" style="color:red; padding:5px;" target="_blank">DELETE ME</a>');
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号