在firebase中使用facebook注册用户

时间:2014-12-12 23:51:58

标签: javascript facebook-graph-api firebase

大家好我正在尝试使用facebook connect botton在我的应用中注册用户。那是当用户点击按钮我检查它是否是第一次我存储他的一些信息,如果它不是他第一次我刚刚进入应用程序。现在我可以记录用户当他点击按钮得到他的信息显示吼叫。 我的问题是在我的Firebase应用中保存这些信息,但它无效。请任何帮助都很棒

//Here is the snapshot of my controller



var app = angular.module("yopi", ["firebase"]);
    app.controller("EventCtrl", function($scope, $firebase, $window) {
      var ref = new Firebase("https://yopi.firebaseio.com/");


      window.fbAsyncInit = function() {
        FB.init({
          appId      : 'MY API', // Set YOUR APP ID/
          status     : true, // check login status
          cookie     : true, // enable cookies to allow the server to access the session
          xfbml      : true  // parse XFBML
        });

        FB.Event.subscribe('auth.authResponseChange', function(response) 
        {
         if (response.status === 'connected') 
        {
            document.getElementById("message").innerHTML +=  "<br>Connected to Facebook";
            //SUCCESS

        }    
        else if (response.status === 'not_authorized') 
        {
            document.getElementById("message").innerHTML +=  "<br>Failed to Connect";

            //FAILED
        } else
        {
            document.getElementById("message").innerHTML +=  "<br>Logged Out";

            //UNKNOWN ERROR
        }
        }); 

        };

        $scope.Login = function()
        {

            FB.login(function(response) {
               if (response.authResponse) 
               {
                    getUserInfo();
                    getPhoto();
                    $window.location.href = "https://yopevent.firebaseapp.com/events.html";
                } else 
                {
                 console.log('User cancelled login or did not fully authorize.');
                }
             },{scope: 'email,user_photos,user_videos'});

        }

      function getUserInfo() {
            FB.api('/me', function(response) {

              UserId = response.id;
              UserName = response.name;
              UserEmail = response.email;

        });
        }

        function getPhoto()
        {
          FB.api('/me/picture?type=normal', function(response) {


                $scope.Id = UserId;
                    $scope.Name = UserName;
                    $scope.Email = UserEmail;
                    $scope.PicUrl = response.data.url;

                    var newUser = {
                      UserId: $scope.Id,
                      UserName: $scope.Name,
                      UserEmail: $scope.Email,
                      UserPicUrl: $scope.PicUrl
                    };

//Here no probleme Iamgeting the oblect correctly in the console.


console.log(newUser);

//but the problem is here this is not svaing this objet in firebase
    ref.child("users").child($scope.Id).set(newUser);

    var str="<br/><b>Pic</b> : <img src='"+response.data.url+"'/>";
    document.getElementById("status").innerHTML+=str;


    });

  }

       $scope.Logout = function()
        {
            FB.logout(function(){document.location.reload();});
        }

      // Load the SDK asynchronously
      (function(d){
         var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
         if (d.getElementById(id)) {return;}
         js = d.createElement('script'); js.id = id; js.async = true;
         js.src = "//connect.facebook.net/en_US/all.js";
         ref.parentNode.insertBefore(js, ref);
       }(document));
    });

0 个答案:

没有答案