public
Last active

  • Download Gist
fb-js-sdk-backup.html
HTML
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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
<script>
var User;
 
User = (function() {
var likesParams;
 
User.name = 'User';
 
function User(authResponse, authorized) {
if (authResponse == null) authResponse = {};
if (authorized == null) authorized = false;
 
if (authResponse.accessToken) {
setAuthData(authResponse);
} else {
this.authorized = false;
}
}
 
User.prototype.setAuthData = function(authResponse) {
this.id = authResponse.userID;
this.accessToken = authResponse.accessToken;
this.authorized = true;
};
 
User.prototype.login = function() {
var getAuthdata, self;
 
self = this;
getAuthdata = this.setAuthData;
 
FB.login(
function (response) {
if (response.authResponse) {
getAuthdata.call(self, response.authResponse);
}
},
{ scope: 'user_likes' }
);
};
 
User.prototype.isAuth = function() {
var getAuthdata, self;
 
self = this;
getAuthdata = this.setAuthData;
 
FB.getLoginStatus( function(response) {
if (response.status === 'connected') {
getAuthdata.call(self, response.authResponse);
}
});
 
return this.authorized;
};
 
likesParams = function() {
var params = 'me/likes?fields=picture.width(125).height(125),name,likes,description,link,category&limit=1000';
 
return params + ("&access_token=" + this.accessToken);
};
 
User.prototype.setLikes = function(data) {
this.likes = data;
};
 
User.prototype.getLikesFromAPI = function() {
var getLikes, params, self;
 
self = this;
params = likesParams.call(self);
getLikes = this.setLikes;
 
FB.api(params, function(response) {
getLikes.call(self, response.data);
});
};
 
User.prototype.likesByCategory = function(data) {
return _.groupBy(this.likes, function(liked) {
return liked.category;
});
};
 
return User;
})();
 
var user = new User();
 
if (user.isAuth()) {
console.log('yes');
user.getLikesFromAPI();
console.log(user)
} else {
console.log('no');
user.login();
}
</script>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.