有人用过ng2-facebook-sdk这个组件吗?如果是这样,有人知道我将如何使用 .api 方法从图形 api 中获取用户数据。 这是 npm 包自述文件指南的链接。我不明白如何使用它 - https://www.npmjs.com/package/ng2-facebook-sdk . 我的问题是我已成功登录用户,但我无法编写返回 Promise 对象的 .api 函数
目前我的代码看起来像这样......
import { Component } from "@angular/core";
import {FacebookService, FacebookInitParams} from "ng2-facebook-sdk";
import { Http } from "@angular/http";
import * as http from "selenium-webdriver/http";
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
name = "";
isUser = false;
no = false;
constructor(private _facebookService: FacebookService,private http:Http) {
let fbParams: FacebookInitParams = {
appId: 'xxxxxxxxxxxxxxx',
xfbml: true,
version: 'v2.6'
};
this._facebookService.init(fbParams);
}
login() {
this._facebookService.login().then((response) => {
this.getUserData();
console.log(response);
});
}
getUserData(){
this._facebookService.api('/me', http,(res) {
this.name = res.name;
this.isUser = true;
});
}
}
最佳答案
我自己想通了。我没有正确处理 Promise 对象响应。 这应该是登录功能 ->
login() {
this._facebookService.login().then((response) => {
var promise = this._facebookService.api('/me');
promise.then((res)=> {
this.id = res.id;
this.name = res.name;
this.isUser = true ;
console.log(res);
});
console.log(response);
});
关于facebook - angular2 无法在 ng2-facebook-sdk 中使用 api 方法来获取用户数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41821165/