【问题标题】:ngFacebook not working with phonegapngFacebook 无法使用 phonegap
【发布时间】:2018-04-06 10:41:39
【问题描述】:

我在我当前的 Angular 应用程序中使用 Almog Baku 的 ngFacebook。在测试环境中它工作正常。但是在通过 phonegap 构建的 apk 中它不起作用。我已经包含了

<dependency id="cordova-plugin-inappbrowser" />

<feature name="InAppBrowser">
<param name="android-package" value="org.apache.cordova.InAppBrowser" />
</feature>
<feature name="InAppBrowser">
<param name="ios-package" value="CDVInAppBrowser" />
</feature>

也进入我的config.xml,但仍然没有 InAppBrowser 或新标签弹出。

我的App.js

var myApp = angular.module('myApp', [
    'ngTouch',
    'ngRoute',
    'myApp.controllers',
    'ngIdle',
    'ngFileUpload',
    'ng.deviceDetector',
    'oitozero.ngSweetAlert',
    'angular-hmac-sha512',
    'ngFacebook'
]);
myApp.config( function( $facebookProvider ) {
    $facebookProvider.setAppId('1869339203095182');
});

在我的控制器中:

$scope.login =  function() {
$facebook.login().then(function() {
  refresh();
});
}
$rootScope.$on('event:social-sign-in-success', function(event, userDetails){
 console.log(userDetails);
})
function refresh() {
  $facebook.api("/me",{fields: 'id,name,email'}).then( 
      function(response) 
      {
            //console.log( response );
      },
      function(err) {
          console.log(err);
        //$scope.welcomeMsg = "Please log in";
      }
  ); 
}
refresh();

【问题讨论】:

  • 它在测试环境中工作,但在 apk 构建中不工作。甚至没有弹出任何东西。
  • @RameshRajendran 如果您可以为这个问题设置赏金,那将是非常大的帮助。
  • 赏金到了我会去做的。
  • @RameshRajendran 伙伴现在请添加一些赏金......

标签: javascript angularjs cordova phonegap-plugins phonegap


【解决方案1】:

移动设备上的 Javascript 不适用于社交媒体。它的发生主要是因为安全限制、证书等。请记住,在应用程序在 AppsStore 或 Google Play 中发布后,您可以通过加载新的 javascript 代码来欺骗业务逻辑。我相信 Facebook 会阻止移动设备上的 javascript 实现。

一些 Cordova 应用程序,例如 US Bank ..,甚至不使用 $httpajax,因为缺少 SSL Pinning,它们对大多数模块使用本地实现。

不想让人失望,但是……看看这个问题:Does not works on cordova android project 2015 年 6 月 4 日开业

我尝试在移动应用上使用 ngFacebook,但它不起作用。我在台式机上测试过,效果很好


你想达到什么目标?如果您只需要登录,请尝试official plugin for Facebook in Apache Cordova/PhoneGap - 它使用原生 Facebook 插件。或cordova-plugin-facebook4

【讨论】:

    【解决方案2】:

    对于社交媒体集成,您应该使用官方cordovaOauth。你可以找到所有关于它的文档here。但是要使用它,您应该包括

    <script src="lib/ng-cordova.js"></script>
    <script src="cordova.js"></script>
    

    这些到你的index.html。在你的控制器调用中应该是:

    $scope.login =  function() {
    $cordovaOauth.facebook("YOUR_APP_ID", ["email","public_profile", "user_friends"]).then(function(result) {
        $http.get("https://graph.facebook.com/me", { params: { access_token: result.access_token, fields: "id,name,email,gender,location,website,picture,relationship_status", format: "json" }}).then(function(result1) {
    //this is success call
    //console.log(result1)
    }, function(error) {
    alert("There was a problem getting your profile. Check the logs for details.");
    console.log(error);
    });
    }, function(error) {
    console.log(error);
    }); 
    }
    

    希望这会对您有所帮助。更详细的信息可以通过ng-cordova.js这个文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-30
      • 2013-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-14
      相关资源
      最近更新 更多