我是巴斯伯克的新手。我遵循了文档并创建了下面的代码来注册社交登录。
这是我的注册代码,可以从各自的社交网络获得令牌。
$scope.createUserWithBaasbox = function(t,social,isLink){
var token = t;
var headers = {'X-BAASBOX-APPCODE':1234567890}
if(isLink){
alert("entered if");
headers['X-BB-SESSION'] = auth.getToken();
}
alert("entered $apply method");
$http({
method:'POST',
headers: headers,
url: serverUrl+"/social/"+social+"?oauth_token="+token+"&oauth_secret="+token,
data:{}
}).success(function(data){
alert("success");
if(!isLink){
alert("success"+JSON.stringify(data));
var userSessionValue = data['data']['X-BB-SESSION'];
//alert(userSessionValue);
var visibleByRegisteredUsers = data['data'].visibleByRegisteredUsers;
if(visibleByRegisteredUsers.email == undefined){
alert(JSON.stringify(visibleByRegisteredUsers));
visibleByRegisteredUsers.email = data['data'].visibleByTheUser.email;
//alert(visibleByRegisteredUsers.email);
visibleByRegisteredUsers.type = "SUBSCRIBER";
visibleByRegisteredUsers.redeemedCount = 0;
visibleByRegisteredUsers.name = data['data'].visibleByTheUser.name;
visibleByRegisteredUsers.dateOfBirth = "";
visibleByRegisteredUsers.emailSubscription = true;
//alert("heyyy"+JSON.stringify(visibleByRegisteredUsers));
visibleByRegisteredUsers.shareCount = 0;
if(social == 'facebook'){
visibleByRegisteredUsers.gender = data['data'].visibleByTheUser.gender;
}
else{
visibleByRegisteredUsers.gender = "";
}
//alert(JSON.stringify(visibleByRegisteredUsers));
$http({
method:'PUT',
url: serverUrl+"/me",
data:{"visibleByRegisteredUsers" : visibleByRegisteredUsers},
headers: {'Content-Type': 'application/json',
'X-BB-SESSION' : data['data']['X-BB-SESSION']
}
}).success(function(data){
alert(data);
//TODO:local storage has to be implemented
$state.go("app.dummy");
//console.log(JSON.stringify(data));
})
.error(function(data){
alert("error block is",data);
//console.log(JSON.stringify(data));
})
}
//alert("not entered into if loop");
//TODO:local storage has to be implemented
$state.go('app.dummy');
//auth.setUser(data["data"].user,{"sso":social,"auth_token":token,"auth_secret":token},data["data"]["X-BB-SESSION"]);
//$location.path("/posts")
}
else{
//alert("loaf from exixting");
//auth.getLogins().push(social);
}
}).error(function(data){
alert("error block is:"+JSON.stringify(data));
console.log(JSON.stringify(data));
})
alert("before $scope.$apply");
}它执行http方法并进入错误函数并以“”的形式返回数据。有人能帮我吗?
发布于 2015-07-20 14:27:52
我忘了把
<access-origin="*">在config.xml中。因此,它不允许http请求获得响应。
https://stackoverflow.com/questions/31321193
复制相似问题