Last active
February 21, 2024 11:37
-
-
Save monokaijs/822dd4b53a88dab70aad44816366cc63 to your computer and use it in GitHub Desktop.
Scan Facebook Messages for attachments.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(() => { | |
/* | |
Author: @MonokaiJsp (MonokaiJs | https://omfg.vn) | |
>>>>>>> Free for Personal Usage. | |
======= Donate me: https://omfg.vn/donate | |
======= Github: https://github.com | |
======= Gists | |
*/ | |
const participant = ''; // Example: 100024036977223 | |
const conversations_count = 1; // 1 recent person | |
const mime_types = ['audio/aac', 'image/jpeg']; // Mime Type Filter | |
var get_list_conversations = (token) => { | |
ajax('https://graph.facebook.com/me/threads?fields=link&limit='+conversations_count+'&access_token=' + token, (data) => { | |
var found = false; | |
var list_conversations = JSON.parse(data).data; | |
for (conv_pos in list_conversations) { | |
let conv = list_conversations[conv_pos]; | |
if (conv.link.includes(participant)) { | |
let url = 'https://graph.facebook.com/' + conv.id + '/messages?fields=attachments&access_token='+token; | |
var scan_data = url => { | |
ajax(url, (data) => { | |
let messages = JSON.parse(data).data; | |
messages.forEach((msg) => { | |
if (typeof msg.attachments !== 'undefined') { | |
msg.attachments.data.forEach((attachment) => { | |
if (mime_types.includes(attachment.mime_type)) { | |
console.log('[' + msg.created_time + '] [' + attachment.mime_type + '] ' + ((typeof attachment.image_data === 'undefined')?attachment.file_url:attachment.image_data.url)); | |
} | |
}); | |
} | |
}); | |
if (typeof JSON.parse(data).paging.next !== 'undefined') { | |
scan_data(JSON.parse(data).paging.next); | |
} else { | |
console.log('> Done!!!'); | |
} | |
}, (e) => { | |
console.log('Failed to retrieve messages!'); | |
}); | |
} | |
scan_data(url); | |
found = true; | |
break; | |
} | |
} | |
if (!found) { | |
console.log('Can not find that conversation!'); | |
} | |
}, (err) => { | |
console.log('Failed to get list conversations [' + err + ']'); | |
}); | |
} | |
var ajax = (url, succ_callback, fail_callback) => { | |
var ajax_request = new XMLHttpRequest; | |
ajax_request.onreadystatechange = () => { | |
if (ajax_request.readyState == 4) { | |
if (ajax_request.status == 200) { | |
succ_callback(ajax_request.responseText); | |
} else { | |
fail_callback(ajax_request.status); | |
} | |
} | |
} | |
ajax_request.open('GET', url); | |
ajax_request.send(); | |
} | |
var get_token = (callback) => { | |
var fb_dtsg = document.getElementsByName('fb_dtsg')[0].value; | |
var http = new XMLHttpRequest; | |
var data = new FormData(); | |
data.append('fb_dtsg', fb_dtsg); | |
data.append('app_id', '165907476854626'); | |
data.append('redirect_uri', 'fbconnect://success'); | |
data.append('display', 'popup'); | |
data.append('ref', 'Default'); | |
data.append('return_format', 'access_token'); | |
data.append('sso_device', 'ios'); | |
data.append('__CONFIRM__', '1'); | |
http.open('POST', 'https://www.facebook.com/v1.0/dialog/oauth/confirm'); | |
http.send(data); | |
http.onreadystatechange = function(){ | |
if(http.readyState == 4 && http.status == 200){ | |
var http2 = new XMLHttpRequest; | |
http2.open('GET', 'https://b-api.facebook.com/restserver.php?method=auth.getSessionForApp&format=json&access_token='+http.responseText.match(/access_token=(.*?)&/)[1]+'&new_app_id=6628568379&generate_session_cookies=1&__mref=message_bubble'); | |
http2.send(); | |
http2.onreadystatechange = function(){ | |
if(http2.readyState == 4 && http2.status == 200){ | |
var http3 = new XMLHttpRequest; | |
var token = JSON.parse(http2.responseText).access_token; | |
callback(token); | |
} | |
} | |
} | |
} | |
} | |
get_token(get_list_conversations); | |
// return false; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment