如何使用 Angular 从 Graph Api 获取 Facebook 额外用户数据?

How to get Facebook extra user data from Graph Api using Angular?

我正在关注文档 here

我的代码是这样的:

async loginWithFacebook() {
    var result = await this.afAuth.signInWithPopup(new auth.FacebookAuthProvider())

    var user = result.user

    let token = (<any>result).credential.accessToken;

    this.getFacebookData(user.uid, token).subscribe(result => {
      console.log(result)
    })
  }

getFacebookData(userId, accessToken) {
    return this.http.get(`https://graph.facebook.com/${userId}
    ?fields=birthday,email,hometown
    &access_token=${accessToken}`, { headers: new HttpHeaders({
      'Authorization': '{data}',
      'Content-Type' : 'application/json'
    })})
  }

我收到这个错误:

{
  "error": {
    "message": "(#803) Some of the aliases you requested do not exist: xxxxxxxxxxxx",
    "type": "OAuthException",
    "code": 803,
    "fbtrace_id": "xxxxxxxxx"
  }
}

我的 Facebook 登录正常,但我想获取额外的数据。 我总是收到 404 或未找到错误。 我究竟做错了什么? 我是否使用了正确的用户 ID 和生成的令牌? 非常感谢您的帮助。干杯!

编辑 1:显示错误。

第一个问题,404 响应,可能是由于 API URL 中的换行符造成的,因此请删除这些。

“您请求的某些别名不存在”是因为 user.uid 是 firebase 内部用户 ID,而不是 Facebook 用户 ID。您可以使用别名 /me 而不是实际用户 ID,它将自动解析为令牌所属的用户(或页面)。

如果您没有获得请求的数据字段,那么很可能到目前为止您还没有为必要的权限添加用户。