2017-08-04 40 views
0

在我的AngularJS項目中,我有fb登錄,並且我正在使用angularjs-socil-login插件。當成功登錄時,我將存儲訪問令牌。如何在AngularJS中設置點擊事件函數setInterval

問題

FB的訪問令牌是一些times.thats後過期,爲什麼我雖然更新使用AngularJs setInterval。然後我已編輯angularjs-socil-login pluging並添加reLogin function.that功能檢查登錄status.if用戶已經令牌連接,我打電話FB.login功能和更新訪問令牌。

這是工作正常,當我到按鈕click.but設置$scope.sign功能,當我在設置$scope.sign功能AngularJS setInterval這不是working.it不是調用FB.login function.Chrome控制檯只顯示hiiiiii fb消息

控制器。 JS

$scope.sign = function(){ 
    $rootScope.newToken=""; 
    socialLoginService.reLogin(); 
    if($rootScope.newToken){ 
    console.log("updated ",$rootScope.newToken); 
    } 
} 

setInterval(function(){ 
$scope.sign(); 
}, 3000); 

到angularjs-socil登錄添加功能(重新登錄)pluging

reLogin:function($q){ 
      console.log("hiiiiii fb"); 

      FB.getLoginStatus(function(response) { 
       if(response.status === "connected"){ 

         FB.login(function(response) { 
          if(response.status === "connected"){ 

            $rootScope.newToken=response.authResponse.accessToken; 
            console.log("updated ",$rootScope.newToken); 

          } 
         }, {scope: 'email', auth_type: 'rerequest'}); 

       }else{ 

       } 
      }); 
     } 
+0

或者你也可以延長Facebook的訪問令牌的到期時間(搜索做對計算器的方式)。 –

+0

Facebook的客戶端SDK應該能夠自動管理它,只要用戶在您的應用中處於活動狀態,他們就會發現您始終擁有新的工作令牌。 _「fb訪問令牌會在某些時間後過期。這就是爲什麼我要更新令牌」_ - 是否有任何實際需要這樣做,否則在某些情況下會出現錯誤,否則......? – CBroe

回答

1
$scope.sign = function(){ 
    $rootScope.newToken=""; 
    socialLoginService.reLogin(); 
    if($rootScope.newToken){ 
    console.log("updated ",$rootScope.newToken); 
    } 
} 

$interval(function(){ 
$scope.sign(); 
}, 3000); 


use $interval instead of setInterval and inject $interval 
相關問題