Ionic - Angular - Ionic-native facebook:预期有 2 个参数,但得到 4 个
Ionic - Angular - Ionic-native facebook: expected 2 arguments, but got 4
我安装了 cordova 插件 facebook4 和 ionic-native/facebook,但是使用插件的 api() 方法时出错,记录在 here.
插件运行良好,但出现 TypeScript 错误:
Typescript Error Expected 2 arguments, but got 4.
这一行:
.then((res: FacebookLoginResponse) => this.fb.api(res.authResponse.userID + "/?fields=id,email,first_name&access_token="+res.authResponse.accessToken+"", ["public_profile"],
根据 this 示例,api 方法采用 4 个参数,对图形的请求 API 以及所需的字段,用于字段的权限,和两个成功/错误回调。
我不知道这里出了什么问题。
为什么 api() 调用只等待 2 个参数?
我用的是official example from ionic-native documentation.
这是我的代码:
fbLogin(): void {
var self = this;
this.fb.login(['public_profile', 'email'])
.then((res: FacebookLoginResponse) => this.fb.api(res.authResponse.userID + "/?fields=id,email,first_name&access_token="+res.authResponse.accessToken+"", ["public_profile"],
(result) => {
let user = new NmUser({
email: result.email,
username: result.firstName,
password: result.id
});
self.userService.facebook(user).subscribe(
(result) => {
console.log(result);
},
(error) => {
console.log(error);
}
);
}, (error) => {
console.error("Failed: ", error);
}
))
.catch(e => console.log('Error logging into Facebook', e));
}
有人知道吗?
在此先感谢所有愿意花时间来 read/answer 的人!
您可以简单地检查
中发生了什么
/node_modules/@ionic-native/facebook/index.d.ts
'api'方法的定义是:
api(requestPath: string, permissions: string[]): Promise<any>;
这意味着它正好需要两个参数和 returns 一个 Promise。
您应该修改您的代码以按以下方式使用另一个 .then(...).catch(...) 方法:
fbLogin(): void {
var self = this;
this.fb.login(['public_profile', 'email'])
.then((res: FacebookLoginResponse) =>
this.fb.api(res.authResponse.userID + "/?fields=id,email,first_name&access_token="+res.authResponse.accessToken+"", ["public_profile"])
.then((result) => {
//process fb.api result
}).catch(e => {
//process fb.api error
})
)
.catch(e => console.log('Error logging into Facebook', e));
}
我安装了 cordova 插件 facebook4 和 ionic-native/facebook,但是使用插件的 api() 方法时出错,记录在 here.
插件运行良好,但出现 TypeScript 错误:
Typescript Error Expected 2 arguments, but got 4.
这一行:
.then((res: FacebookLoginResponse) => this.fb.api(res.authResponse.userID + "/?fields=id,email,first_name&access_token="+res.authResponse.accessToken+"", ["public_profile"],
根据 this 示例,api 方法采用 4 个参数,对图形的请求 API 以及所需的字段,用于字段的权限,和两个成功/错误回调。
我不知道这里出了什么问题。
为什么 api() 调用只等待 2 个参数?
我用的是official example from ionic-native documentation.
这是我的代码:
fbLogin(): void {
var self = this;
this.fb.login(['public_profile', 'email'])
.then((res: FacebookLoginResponse) => this.fb.api(res.authResponse.userID + "/?fields=id,email,first_name&access_token="+res.authResponse.accessToken+"", ["public_profile"],
(result) => {
let user = new NmUser({
email: result.email,
username: result.firstName,
password: result.id
});
self.userService.facebook(user).subscribe(
(result) => {
console.log(result);
},
(error) => {
console.log(error);
}
);
}, (error) => {
console.error("Failed: ", error);
}
))
.catch(e => console.log('Error logging into Facebook', e));
}
有人知道吗?
在此先感谢所有愿意花时间来 read/answer 的人!
您可以简单地检查
中发生了什么/node_modules/@ionic-native/facebook/index.d.ts
'api'方法的定义是:
api(requestPath: string, permissions: string[]): Promise<any>;
这意味着它正好需要两个参数和 returns 一个 Promise。
您应该修改您的代码以按以下方式使用另一个 .then(...).catch(...) 方法:
fbLogin(): void {
var self = this;
this.fb.login(['public_profile', 'email'])
.then((res: FacebookLoginResponse) =>
this.fb.api(res.authResponse.userID + "/?fields=id,email,first_name&access_token="+res.authResponse.accessToken+"", ["public_profile"])
.then((result) => {
//process fb.api result
}).catch(e => {
//process fb.api error
})
)
.catch(e => console.log('Error logging into Facebook', e));
}