我正在将AngularJS用于我的客户端应用程序。我准备好让我的apis被前端应用程序使用,但我想我不知道如何正确地调用它们。我有一个登录api,由fbLogin从前端调用。我的控制器和服务的正面实现是这样的。
controller.js
FB.login(function(response) {
if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', 'GET',{fields:'email,first_name,name,id,picture'}, function(response) {
console.log('Good to see you, ' + response.name + '.');
console.log(response);
$scope.$apply(function(){
$scope.facebook.username=response.name;
$scope.facebook.email=response.email;
$scope.fb_image=response.picture.data.url;
});
var accessToken=FB.getAuthResponse();
var facebookAuthenticationObject={
'access_token':accessToken.accesToken,
'id':accessToken.userID,
'app_platform':'web',
'provider':'facebook'
}
authenticationService.login(facebookAuthenticationObject)
.then(function(response){
$scope.jwt_token=response
})
console.log(accessToken);
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
},{
scope:'email,user_likes',
return_scopes:true
});
}
services.js
angular.module('workit.services',[])
.factory('authenticationService', ['$http', function($http) {
var url = 'localhost:5000/api/auths/login';
var authenticationService = {};
authenticationService.login=function(authObject){
return $http.post(url,authObject);
}
return authenticationService;
}])
;
谁能告诉可能是什么问题?我的api是100%正确的,因为我使用邮递员打电话,它给出了一个成功的响应,但我无法通过我的客户端实现实现它。任何帮助将非常感激。非常感谢!!
完整错误:
" XMLHttpRequest无法加载http://localhost/api/auths/login。无效 响应。起源' http://192.168.150.130:8081'因此不是 允许访问。"
可能未经处理的拒绝: {"数据":空,"状态": - 1,"配置" {"方法":" POST&#34 ;," transformRequest":[空]," transformResponse":[空]," jsonpCallbackParam":"回调""网址":" http://192.175.117.177:5000/api/auths/login""数据&#34 ;: {" ID":" 10210782205725002"" APP_PLATFORM":"网络""提供商":" Facebook和#34;}"头" {"接受":"应用/ JSON, text / plain的, / ""内容类型":"应用/ JSON;字符集= UTF-8"}},"状态文本&#34 ;:""}