forked from daattali/advanced-shiny
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
68 lines (60 loc) · 1.97 KB
/
app.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
// Dean Attali, July 2015
facebook = function() {
return {
init : function() {
// initialize facebook JDK
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
window.fbAsyncInit = function() {
FB.init({
appId: '587632811407957', // YOUR APP ID GOES HERE
cookie: true,
version: 'v2.7'
});
FB.getLoginStatus(function(response) {
console.log(response);
facebook.statusChangeCallback(response);
});
};
// register click handler to login
$('#fbLoginBtn').click(function() {
facebook.fbLogin(function(response) {
var params = {};
params['_method'] = 'fblogin';
params['_callback'] = function(r){console.log(r)};
params['user_id'] = response.authResponse.userID;
params['access_token'] = response.authResponse.accessToken;
api.call(params);
});
});
},
fbLogin : function(cb) {
FB.login(function(response) {
facebook.statusChangeCallback(response, cb);
});
},
// This is called with the results from from FB.getLoginStatus().
statusChangeCallback : function(response, cb) {
console.log(response);
if (response.status === 'connected') {
FB.api('/me', function(response) {
$("#fbStatus").html('Hi ' + response.name);
});
if (typeof cb !== "undefined") {
cb(response);
}
} else if (response.status === 'not_authorized') {
$("#fbStatus").html('Please authorize the app.');
} else {
$("#fbStatus").html('Please log into Facebook.');
}
},
}
}();
$(function () { facebook.init(); });