我正在开发离子-1的应用程序。我还实现了facebook登录插件。我跟着this steps。我没有错误,但是当我点击facebook按钮时,它不起作用,没有错误显示。我在每个错误捕获中使用<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div class="group-box">
<p>test1</p>
<div class="group-box">
<p>test2</p>
<div class="group-box">
<p>test3</p>
</div>
</div>
</div>
但不会显示警报。
注意:我在一个真正的Android设备上运行,因为他们说本机插件无法在浏览器中运行。
请帮助我,因为我正在处理我的论文。谢谢你们所有人!
这是我的代码:
alert
在我的HTML中
.controller('CreateAccountCtrl', ['$scope','$http','$state','$q','UserService','$stateParams', '$ionicLoading','$timeout','$ionicPopup',function($scope, $http,$state,$q, UserService,$stateParams,$ionicLoading,$timeout,$ionicPopup){
$scope.$on('$ionicView.beforeEnter', function(e){
$ionicLoading.show({
animation: 'fade-in', showBackdrop: true
});
});
$scope.$on('$ionicView.afterEnter', function(e){
$ionicLoading.hide();
$scope.formData = {};
$scope.showAlert = function(ttl,msg){
var alertPopup = $ionicPopup.alert({
title: ttl,
template: msg
});
};
});
// facebook
// This is the success callbak from the login method
var fbLoginSuccess = function(response){
if(!response.authResponse){
fbLoginError("Cannot find the authResponse");
return;
}
var authResponse = response.authResponse;
getFacebookProfileInfo(authResponse)
.then(function(profileInfo){
// store user data on local storage
UserService.setUser({
authResponse: authResponse,
userID: profileInfo.id,
name: profileInfo.name,
email: profileInfo.email,
picture: "http://graph.facebook.com/" + authResponse.userID + "/picture?type=large"
});
$ionicLoading.hide();
$state.go('app.home');
}, function(fail){
alert(fail);
// Fail get profile info
console.log('Profile Info Fail', fail);
});
};
// This is the fail callback from the login method
var fbLoginError = function(error){
console.log('fbLoginError', error);
alert(error);
$ionicLoading.hide();
};
// This method is to get the user profile info from the facebook api
var getFacebookProfileInfo = function(authResponse){
var info = $q.defer();
facebookConnectPlugin.api('/me?fields=email,name&access_token=' + authResponse.accessToken, null,
function(response){
alert(response);
console.log(response);
info.resolve(response);
},
function(response){
console.log(response);
alert(response);
info.reject(response);
}
);
return info.promise;
};
// This method is executed when the user press the "Login with faceboook" button
$scope.facebookSignIn = function(){
alert(1);
facebookConnectPlugin.getLoginStatus(function(success){
if(success.status === 'connected'){
// The user is logged in and has authenticated your app, and response.authResponse supplies
// the user's ID, a valid access token, a signed request, and the time the access token
// and signed request each expire
console.log('getLoginStatus', success.status);
alert(success.status);
// Check if we have our user saved
var user = UserService.getUser('facebook');
if(!user.userID){
getFacebookProfileInfo(success.authResponse)
.then(function(profileInfo){
UserService.setUser({
authResponse: success.authResponse,
userID: profileInfo.id,
name: profileInfo.name,
email: profileInfo.email,
picture : "http://graph.facebook.com/" + success.authResponse.userID + "/picture?type=large"
});
$state.go('app.home');
}, function(fail){
console.log('Profile info fail', fail);
alert(fail);
});
}else{
$state.go('app.home');
}
}else{
// If (success.status === 'not_authorized') the user is logged in to Facebook,
// but has not authenticated your app
// Else the person is not logged into Facebook,
// so we're not sure if they are logged into this app or not.
console.log('getLoginStatus', success.status);
alert(success.status);
$ionicLoading.show({
template: 'Logging in...'
});
facebookConnectPlugin.login(['email','public_profile'], fbLoginSuccess, fbLoginError);
}
});
};
}]);
答案 0 :(得分:0)
APP_NAME =“必须是在Facebook开发者处创建的facebook应用程序名称,而不是您的应用名称” APP_ID = facebook app id。
使用facebook v4安装 $ cordova插件添加cordova-plugin-facebook4 --save --variable APP_ID =“123456789” - 变量APP_NAME =“myApplication”
$rootScope.loginFacebook = function() {
$cordovaFacebook.login(["public_profile", "email", "user_birthday", "user_photos"]).then(function(success){
console.info(success.status);
if (success.status === 'connected') {
var checkrequest = {
'AuthSession[device_token]': $localStorage.device_token
}
appname.check(checkrequest).then(function(response) {
console.log(response);
if (response.key == "NOAUTH") {
$state.go('main.allowPush')
}
})
} else if (success.status === 'not_authorized') {
console.info('the user is logged in to Facebook but has not
authenticated your app')
} else {
console.info('the user is nott logged in to Facebook')
}
}, function(error) {
console.info(error);
});
}