-
Notifications
You must be signed in to change notification settings - Fork 26
/
run_example.js
69 lines (63 loc) · 2.93 KB
/
run_example.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
var http = require('http');
var FacebookClient = require("./lib/facebook-client").FacebookClient;
http.createServer(function (request, response) {
var app_id = "yourappid"; // configure like your fb app page states
var facebook_client = new FacebookClient(
app_id,
"yourappsecret" // configure like your fb app page states
);
facebook_client.getSessionByRequestHeaders(request.headers)(function(facebook_session) {
if (!facebook_session)
{
response.writeHead(200, {'Content-Type': 'text/html'});
response.write([
'<html>',
'<head><title>node-facebook-client example</title></head><body>',
'<p>Login please</p> <fb:login-button autologoutlink="true"></fb:login-button>',
'<div id="fb-root"></div>',
'<script type="text/javascript">',
'window.fbAsyncInit = function() {',
' FB.init({appId: "' + app_id +'", logging:false, status: true, cookie: true, xfbml: true});',
' FB.Event.subscribe(\'auth.sessionChange\', function(response) {',
' document.location = document.location.href;',
' });',
'};',
'(function() {',
' var e = document.createElement(\'script\'); e.async = true;',
' e.src = document.location.protocol +',
' \'//connect.facebook.net/en_US/all.js\';',
' document.getElementById(\'fb-root\').appendChild(e);',
'}());',
'</script>',
'</body>',
'</html>'
].join("\n"));
response.end();
return ;
}
/*
* Graph-API
*/
response.writeHead(200, {'Content-Type': 'text/plain'});
facebook_session.isValid()(function(is_valid) {
if (!is_valid)
{
response.write('Session expired or user logged out.' + "\n");
response.end();
return ;
}
facebook_session.graphCall("/me", {
})(function(result) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.write('By using Graph API:' + "\n");
response.write(' Name:' + result.name + "\n");
response.write(' Id:' + result.id + "\n");
response.write(' Link:' + result.link + "\n");
facebook_session.restCall("fql.multiquery", {"queries": {"query1":"SELECT uid FROM user WHERE uid=" + result.id, "query2":"SELECT name, url, pic FROM profile WHERE id IN (SELECT uid FROM #query1)"}}, {})(function() {
console.log('multiquery', JSON.stringify(arguments[0]));
response.end();
});
});
});
});
}).listen(8000);