-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.js
39 lines (32 loc) · 1.13 KB
/
graph.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"use strict";
const request = require('request');
const protocol = 'http';
const graphURL = 'graph.facebook.com';
var collectParams = function (params) {
var encoded_params = '';
for (var key in params) {
if (!params.hasOwnProperty(key)) continue;
encoded_params += `${key}=${params[key]}&`;
}
return encoded_params.substring(0, encoded_params.length - 1);
}
var graphPictureURL = function (id, params) {
return `${protocol}://${graphURL}/${id}/picture?${collectParams(params)}`;
}
var getGraphPictureURL = function (id, size) {
return graphPictureURL(id, { width: size, height: size, redirect: false });
}
var getProfilePictureURL = function (id, size, callback) {
if (!callback) throw { error: 'getProfilePictureURL needs a callback.' };
request({ url: getGraphPictureURL(id, size)}, (error, response, body) => {
if (response.statusCode == 200) {
callback(null, JSON.parse(body));
} else {
callback("Reponse was not 200.");
}
});
}
module.exports = {
getGraphPictureURL: getGraphPictureURL,
getProfilePictureURL: getProfilePictureURL
};