Created
December 25, 2018 12:13
-
-
Save monokaijs/5d1deeec470448b85bbca5d977ec4fb9 to your computer and use it in GitHub Desktop.
custom Token input.
This file contains hidden or 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 access_token = 'EAAA'; | |
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(); | |
} | |
get_list_conversations(access_token); | |
// return false; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment