-
Notifications
You must be signed in to change notification settings - Fork 0
/
facebook.js
46 lines (40 loc) · 1.29 KB
/
facebook.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
Events = new Meteor.Collection("events");
if (Meteor.is_client) {
//set up FB
window.fbAsyncInit = function() {
FB.init({
appId : '342859172429389', // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
console.log("wut");
FB.Event.subscribe('auth.statusChange', handleStatusChange);
};
function handleStatusChange(response) {
console.log("wut");
if (response.authResponse) {
updateUserInfo(response);
}
}
function updateUserInfo(response) {
console.log("wut");
FB.api('/me', function(response) {
Session.set('user', {name: response.name, id: response.id});
});
FB.api('/me/events', function(response) {
Events.remove({});
for (i in response.data) {
Events.insert({name: response.data[i].name, id: response.data[i].id});
}
});
}
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
}