【问题标题】:Retrieving public profile from Facebook with Firebase and AngularJS使用 Firebase 和 AngularJS 从 Facebook 检索公共个人资料
【发布时间】:2017-05-26 10:17:24
【问题描述】:

所以,我一直在我的 AngularJS/Ionic 项目中使用 Firebase 来通过 Facebook 身份验证访问我的应用程序。

身份验证正常,它检索了一些数据(显示名称、电子邮件、urid、url 照片等),但我需要更多。

我需要获取我的项目的名字和姓氏,因为我需要使用它。当此人接受分享信息时,表示她正在分享她的公开个人资料,但收到的数据并没有 Facebook 文档所说的公开个人资料提供的内容。

我使用 Firebase 文档对此进行了编程。有一部分说使用addScope 添加您想要的内容,默认情况下会询问公共配置文件,但我还是添加了它。 (我发不了链接,StackOverflow 说我的名声太低了)。

$scope.FBLogin = function (){
firebase.auth().signInWithPopup(provider).then(function(result) {

  var token = result.credential.accessToken;
  var user = result.user;
  var profile = result.user.public_profile;
  console.log("success")
  console.log(result);
  console.log(user);


}).catch(function(error) {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;
  // The email of the user's account used.
  var email = error.email;
  // The firebase.auth.AuthCredential type that was used.
  var credential = error.credential;
// ...
});
};

在此处登录:

所以,因为我不想使用“显示名称”。因为人们有时不会在那里使用他们的真实姓名。

有谁知道如何使用 Firebase 和 AngularJS 检索这些信息?

【问题讨论】:

    标签: javascript angularjs firebase firebase-authentication facebook-authentication


    【解决方案1】:

    Firebase 目前不支持此功能。您必须对 Facebook 进行额外的 api 调用才能获取该数据。

    result.credential.accessToken 包含 Facebook 访问令牌。使用该访问令牌,您可以获得 Facebook 个人资料数据。这是一个如何使用 facebook 执行此操作的示例: How to get user profile info using access token in php-sdk

    AJAX GET 'https://graph.facebook.com/me?access_token=' + result.credential.accessToken

    【讨论】:

    • 非常感谢! =) 这就是我要找的。​​span>
    【解决方案2】:

    对于寻找如何在 AngularJS 中执行此操作或如何过滤所需内容的人来说,这是我使用 bojeil 给我的信息的方式!(再次感谢您!)

    var token = result.credential.accessToken;
    var user = result.user;
    
    $http.get('https://graph.facebook.com/v2.5/me?  access_token='+token+'&fields=id,name,first_name,last_name,email')
      .success(function(jsonService){
         $scope.user.firstName= jsonService.first_name;
         $scope.user.lastName= jsonService.last_name
         $scope.user.email = jsonService.email;
      });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-27
      相关资源
      最近更新 更多