Javascript 在angular js应用程序中加载Facebook sdk的推荐方法

Javascript 在angular js应用程序中加载Facebook sdk的推荐方法,javascript,android,angularjs,facebook,facebook-graph-api,Javascript,Android,Angularjs,Facebook,Facebook Graph Api,我在Github使用facebook的angularjs应用程序和这个模块,并像这样初始化它 var mainApp=angular.module('app',['ngMaterial','facebook','services']); mainApp.config(function(FacebookProvider) { // Set your appId through the setAppId method or // use the short

我在Github使用facebook的angularjs应用程序和这个模块,并像这样初始化它

var mainApp=angular.module('app',['ngMaterial','facebook','services']);
    mainApp.config(function(FacebookProvider) {
         // Set your appId through the setAppId method or
         // use the shortcut in the initialize method directly.
         FacebookProvider.init('532389480270701');
      })



    mainApp.controller('StartUpController', ['$http','Facebook','$scope','Product', function($http,Facebook,$scope,Product){

      $scope.user={};
      $scope.mate={};
      $scope.facebookReady=false;
      $scope.login = function() {
          // From now on you can use the Facebook service just as Facebook api says
          Facebook.login(function(response) {
            // Do something with response.
          });
        };

        $scope.getLoginStatus = function() {
          Facebook.getLoginStatus(function(response) {
            if(response.status === 'connected') {
              $scope.loggedIn = true;
            } else {
              $scope.loggedIn = false;
            }
          });
        };

        $scope.me = function() {
          Facebook.api('/me', function(response) {
            $scope.user = response;
          });
        };
        $scope.getMateInfo=function(){
          Facebook.api(
              '/me/picture',
              'GET',
              {},
              function(response) {
                $scope.mate=response;
              }
            );

        };
        $scope.$watch(function() {
          // This is for convenience, to notify if Facebook is loaded and ready to go.
          return Facebook.isReady();
        }, function(newVal) {
          // You might want to use this to disable/show/hide buttons and else
          $scope.facebookReady = true;
        });
在html中,我在页脚的angularjs模块之后加载了该模块

我的问题是UI显示应用程序,单击使用facebook api的内容会导致此错误

{“error”:{“message”:“必须使用活动访问令牌来查询有关当前用户的信息。”,“type”:“OAutheException”,“code”:2500,“fbtrace_id”:“FU8MECrV+3P”}

但过了一段时间,这意味着在加载所有内容后,将显示API的正确结果。 这件事该怎么解决

  • 如果仍在加载资源,如何禁用按钮
  • 如何在显示应用程序的UI之前加载所有资源

  • 谢谢

    我没有将fbapi与js一起使用,但我猜是这样的。 我已经能够在运行$scope.me()之前重现您的错误。您可能需要在身份验证/登录后使用这些功能

    // do not show all buttons at first
    $scope.showOtherButtons = false;
    
    // call Login
    $scope.login()
    ...
    Facebook.login(function(response) {
        // At this point calling $scope.me() should probably be safe.
        $scope.showOtherButtons = true;
    });
    
    在html中,使用指令在验证之前隐藏所有其他按钮,如`

    <div ng-if="showOtherButtons">... buttons are here </div>
    
    。。。按钮在这里
    
    希望这有帮助