Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ngFacebook not working with phonegap

Im using ngFacebook by Almog Baku in my current angular app. In test environment it is working fine. But in apk build via phonegap it isn't working. I have included

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

and

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

into my config.xml too but still no InAppBrowser or new tab poping up.

My App.js is

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');
});

And in my controller:

$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();
like image 563
Debra Avatar asked Oct 25 '17 11:10

Debra


2 Answers

Javascript on mobile doesn't work good with social medias. It happens mostly because of security restrictions, certificates and so on. Keep in mind with Javascript you can fraud business logic by loading new javascript code after application has been published in AppsStore or Google Play. I believe Facebook blocks javascript implementation on mobile devices.

Some Cordova applications, for example US Bank .., even do not use $http or ajaxbecause of lack of SSL Pinning, they use native implementation for most of modules.

Don't want to disappoint but ... take a look on this issue: Does not works on cordova android project opened at Jun 4, 2015

I trying to use ngFacebook on a mobile app but is does not work. I tested on desktop and it works perfect


What do you want to achieve? if you need login only , try official plugin for Facebook in Apache Cordova/PhoneGap - it uses native Facebook plugin. Or cordova-plugin-facebook4

like image 82
Maxim Shoustin Avatar answered Oct 23 '22 18:10

Maxim Shoustin


For social Media Integration You should use official cordovaOauth. You can find all documentation regarding it here. But to use it you should include

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

these into your index.html. And in your controller call should be:

$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);
}); 
}

Hope this will help you. For more detailed information you can go through ng-cordova.js this file.

like image 2
Tech Kid Avatar answered Oct 23 '22 16:10

Tech Kid