错误 API Facebook - Angular 2 和 Ionic 2
Error API Facebook - Angular 2 and Ionic 2
我正在使用 facebook API,我需要获取配置文件数据以将其保存在数据库中。代码 returns 很好,但是当我尝试访问数据时它显示错误,因为它们是空的。
这是我的代码:
this.fb.login(['public_profile', 'user_friends', 'email'])
.then((res: FacebookLoginResponse) => {
token = res.authResponse.accessToken;
userId = res.authResponse.userID;
if (res.status == 'connected') {
this.fb.api('/' + res.authResponse.userID + '?fields=id,first_name,last_name,gender, email,birthday', [],
function onSuccess(result) {
var name = JSON.stringify(result.first_name);
this.register(name);
},
function onError(error) {
console.log(error);
});
} else {
console.log('Not logged in');
}
}).catch(e => console.log('Error logging into Facebook', e));
当我尝试调用 register
方法时,它会生成错误,因为该方法不存在,但事实并非如此。我也尝试将name
的结果保存到一个全局变量中,但是当它被分配时它显示它不能分配变量,即好像没有定义全局变量。
解决办法是改变
function onSuccess(result) {
var name = JSON.stringify(result.first_name);
this.register(name);
},
function onError(error) {
console.log(error);
});
为了
(result) => {
var name = JSON.stringify(result.first_name);
this.register(name);
},
(error) => {
console.log(error);
});
我正在使用 facebook API,我需要获取配置文件数据以将其保存在数据库中。代码 returns 很好,但是当我尝试访问数据时它显示错误,因为它们是空的。
这是我的代码:
this.fb.login(['public_profile', 'user_friends', 'email'])
.then((res: FacebookLoginResponse) => {
token = res.authResponse.accessToken;
userId = res.authResponse.userID;
if (res.status == 'connected') {
this.fb.api('/' + res.authResponse.userID + '?fields=id,first_name,last_name,gender, email,birthday', [],
function onSuccess(result) {
var name = JSON.stringify(result.first_name);
this.register(name);
},
function onError(error) {
console.log(error);
});
} else {
console.log('Not logged in');
}
}).catch(e => console.log('Error logging into Facebook', e));
当我尝试调用 register
方法时,它会生成错误,因为该方法不存在,但事实并非如此。我也尝试将name
的结果保存到一个全局变量中,但是当它被分配时它显示它不能分配变量,即好像没有定义全局变量。
解决办法是改变
function onSuccess(result) {
var name = JSON.stringify(result.first_name);
this.register(name);
},
function onError(error) {
console.log(error);
});
为了
(result) => {
var name = JSON.stringify(result.first_name);
this.register(name);
},
(error) => {
console.log(error);
});