You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
769 B
42 lines
769 B
|
5 years ago
|
const fetch = require('node-fetch');
|
||
|
|
const graphql_endpoint = 'https://www.facebook.com/api/graphql/';
|
||
|
|
|
||
|
|
const do_request = async (doc_id, variables) => {
|
||
|
|
const params = new URLSearchParams();
|
||
|
|
params.append('doc_id', doc_id);
|
||
|
|
params.append('variables', JSON.stringify(variables));
|
||
|
|
|
||
|
|
const fetch_options = {
|
||
|
|
headers: {
|
||
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||
|
|
},
|
||
|
|
body: params,
|
||
|
|
method: 'POST',
|
||
|
|
};
|
||
|
|
|
||
|
|
let res = null;
|
||
|
|
try {
|
||
|
|
res = await fetch(graphql_endpoint, fetch_options);
|
||
|
|
} catch (e) {
|
||
|
|
console.error(e);
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!res.ok) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
try {
|
||
|
|
res = await res.json();
|
||
|
|
} catch (e) {
|
||
|
|
console.error(e);
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
return res;
|
||
|
|
};
|
||
|
|
|
||
|
|
module.exports = {
|
||
|
|
do_request,
|
||
|
|
};
|