angular
.module('app', ['ngFacebook'])
.controller('AppController', ['$scope','FacebookFactory',function($scope,FacebookFactory) {
FacebookFactory.setLang('pt_BR')
FacebookFactory.init({
appId: 'appId',
status: true,
cookie: false,
xfbml: false,
version: 'v2.8'
})
}])
angular
.module('app')
.service('FacebookService', ['$http','FacebookFactory',function($http,FacebookFactory) {
var service = {
me: me,
auth: auth,
logout: logout,
disconnect: disconnect,
share: share
}
return service
function me(callback) {
FacebookFactory.api('/me', {
fields: 'name,email,gender,birthday'
}, function(response) {
callback(response)
})
}
function auth(callback) {
FacebookFactory.getLoginStatus(function(response) {
if (response.status === 'connected') {
callback(response)
} else {
FacebookFactory.login(function(response) {
if (response.status === 'connected') {
callback(response)
}
}, {
scope: 'public_profile,email,user_birthday'
})
}
})
}
function logout(callback) {
FacebookFactory.logout(function(response) {
callback(response)
})
}
function disconnect(callback) {
FacebookFactory.disconnect(function(response) {
callback(response)
})
}
function share(params, callback) {
var obj = {
method: 'share',
mobile_iframe: true
}
FacebookFactory.ui(
Object.assign(obj, params),
function(response) {
callback(response)
}
)
}
}])
angular
.module('app')
.controller('AuthController', ['$scope','FacebookFactory','FacebookService',function($scope,FacebookFactory,FacebookService) {
$scope.getAuth = function(callback) {
FacebookService.auth(function(response) {
$scope.token = response.authResponse.accessToken
FacebookService.me(function(response) {
})
})
}
$scope.logout = function() {
FacebookService.logout(function(response) {
})
}
$scope.disconnect = function() {
FacebookService.disconnect(function(response) {
})
}
$scope.share = function() {
FacebookService.share({
href: 'http://guiseek.js.org/angular-facebook-factory',
title: 'Angular Facebook Factory',
description: 'Facebook factory for AngularJS 1.x'
}, function(response) {
})
}
}])