Last active
December 24, 2018 02:04
-
-
Save monokaijs/eed6874944f29dd463984b9eb3fa7102 to your computer and use it in GitHub Desktop.
Get list of users who has most messages with you.
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
(function () { | |
/* | |
** Written by MonokaiCSS | |
** Editted by MonokaiJs | |
*/ | |
const top_count = 20; // Edit this line for custom number conversations. | |
var get_list_conversations = (token) => { | |
ajax('https://graph.facebook.com/me/threads?fields=message_count,participants&limit=500&access_token=' + token, (data) => { | |
var list_conversations = JSON.parse(data).data; | |
list_conversations.sort((a, b) => { | |
return b.message_count - a.message_count; | |
}); | |
var output_count = 0; | |
var i = 0; | |
while (i < top_count && i < list_conversations.length) { | |
let conversation = list_conversations[i]; | |
let participants = conversation.participants.data; | |
if (participants.length == 2) { | |
output_count ++; | |
console.log('Top ' + (output_count) + ' \t[' + participants[0].id + ']' + ': ' + participants[0].name + ': ' + conversation.message_count); | |
} else { | |
} | |
i++; | |
} | |
}, (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); // <<<<========================== WORK HERE ;) HIHI | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment