-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfb.js
More file actions
82 lines (70 loc) · 1.9 KB
/
fb.js
File metadata and controls
82 lines (70 loc) · 1.9 KB
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
70
71
72
73
74
75
76
77
78
79
80
var Facebook = function(view, callback, fail) {
this.id = 0;
this.login = function() {
var that = this;
FB.login(function(response) {
if (response.authResponse) {
this.id = response.authResponse.userID;
callback(this.id);
} else {
fail();
}
},{
scope: 'friends_location,user_location,friends_photos,user_photos,user_status,friends_status'
});
}
this.logout = function() {
// log the user out
FB.logout();
view.showLogin();
}
this.getFriends = function(cb) {
var that = this;
FB.api('/me', function(me) {
that.me = me;
FB.api('/me/friends', function(response) {
response.data.push(me);
cb(response.data);
});
});
}
this.getPhotoData = function (target, parser) {
view.showSpinner();
var that = this;
var limit = 60;
FB.api(target+"/photos?fields=tags.fields(id,name),likes.fields(name,id)&limit="+limit, function(res) {
parser(res.data, that.id);
view.hideSpinner();
});
}
this.init = function() {
var that = this;
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : '195936307261513', // App ID from the app dashboard
channelUrl : '/channel.html', // Channel file for x-domain comms
status : true, // Check Facebook Login status
xfbml : true // Look for social plugins on the page
});
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated
that.id = response.authResponse.userID;
callback(that.id);
} else {
fail();
}
});
};
// Load the SDK asynchronously
(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/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
}
this.init();
}