2017-01-23 125 views
1

我已经实现了我的离子应用程序的Facebook登录,这在网上运行时完美运行。当我构建应用程序时,创建一个相同的apk,并尝试在我的移动设备上运行,没有任何反应。Ionic Facebook登录为本地

登录为:

openFB.login(
      function (response) { 
       if (response.status === 'connected') { 
        console.log('Facebook login succeeded, got access token: ', response); 

        openFB.api({ 
         path: '/me', 
         success: function (data) { 
          console.log("My Data", data); 
          userData.name = data.name; 
          userData.picture = 'http://graph.facebook.com/' + data.id + '/picture?type=small'; 
          localStorageService.set('user', userData); 
          $timeout(function() { 
           $state.go('app.home'); 
          }, 0); 
         }, 
         error: function(error) { 
          console.log("Error here:", error); 
         } 
        }); 
       } else { 
        console.log('Facebook login failed: ' + response); 
       } 
      }, { scope: 'email, public_profile' }); 

曾用openFB为登录。点击后,弹出窗口出现。

enter image description here

点击还好,没什么之后得到记录。没有控制台消息。

有人可以帮我找出这个问题,我不能在实际设备上运行Facebook登录。

+0

调试代码。然后,如果你不能自己弄清楚,请在这里包含相关的代码和错误消息。没有它,任何人都无法提供帮助。 – raj

+0

@raj:更新了问题 –

回答

0

您需要将重定向网址列入白名单。你可以将它设置在

产品> Facebook的登录>设置>客户端的OAuth设置

看看这个question

+0

已经尝试过。由于我在本地运行我的应用程序,因此我在有效的OAuth重定向URI中提到了http:// localhost。 –

0

请设定在 产品重定向URI>的Facebook登录>设置>客户端的OAuth设置

http://localhost/callback

请按照下面的步骤在Facebook开发人员网站 https://ccoenraets.github.io/ionic-tutorial/ionic-facebook-integration.html

和使用注册您的应用程序下面的代码来完成Facebook登录程序

$cordovaOauth.facebook("appId", ["email", "public_profile"]).then(function(result) { 
//alert(JSON.stringify(result)); 
//$localStorage.accessToken = result.access_token; 
$http.get("https://graph.facebook.com/v2.2/me", { 
    params: { 
     access_token: result.access_token, 
     fields: "id,name,gender,location,email,picture,relationship_status", 
     format: "json" 
    } 
}).then(function(result) { 
    // alert(JSON.stringify(result)); 
    $scope.loginflowusingsociallogin(result.data.email); 
}, function(error) { 
    alert("There was a problem getting your profile. Check the logs for details."); 
    alert(JSON.stringify(error)); 
}); 
}); 

我使用Oauth 2.0认证离子。

+0

此功能用于登录不起作用。已取消注释警报,以检查我是否得到回复。没有警报显示。 –

+0

是否打开Facebook登录页面 –

+0

其开放的Facebook登录页面 –

0

我以前this代码,并使用镀铬的工作对我罚款

+0

我正在使用离子,而不是离子2.任何与离子 –