Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Social = {
- init : function (){
- // 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'));
- window.fbAsyncInit = function() {
- FB.init({
- appId: fb_id,
- cookie: true, // enable cookies to allow the server to access the session
- xfbml: true, // parse social plugins on this page
- version: fb_version // use version 2.1
- });
- $(document).trigger('fbload');
- };
- console.log('Social init run...')
- },
- login: function() {
- var fbOptions = {
- scope: 'email,public_profile'
- };
- /*
- {
- email: "[email protected]"
- first_name: "xxx"
- gender: "xxx"
- id: "xxx"
- last_name: "xxx"
- link: "xxx/xxx/"
- locale: "en_US"
- name: "xxx"
- timezone: 7
- updated_time: "xxx"
- verified: true
- }
- */
- FB.login(function(response) {
- if (response.status == 'connected' && response.authResponse) {
- FB.api('/me', function(me) {
- console.log(me); // dump complete info
- var entity = {
- facebook_id : response.authResponse.userID,
- facebook_url : me.link,
- facebook_token: response.authResponse.accessToken,
- firstname: me.first_name,
- lastname : me.last_name,
- email : me.email,
- gender : me.gender == 'male' ? 'm' : 'f',
- };
- });
- } else {
- //user hit cancel button
- console.log('User cancelled login or did not fully authorize.');
- }
- }, fbOptions);
- },
- share: function() {
- FB.ui({
- method: 'share',
- href: window.location.href
- }, function(response){
- // window.location.reload();
- });
- },
- like: function() {
- FB.login(function(){
- FB.api(
- "/me/og.likes",
- "POST",
- {
- "object": window.location.href
- },
- function (response) {
- if (response && !response.error) {
- /* handle the result */
- // toastr['success']('result.error');
- }
- });
- }, {scope: 'publish_actions'});
- },
- logout: function() {
- FB.logout(function() {
- window.location.reload();
- });
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment