Click here to Skip to main content
15,881,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need help to implement Facebook login within my application. I tried the official Cordova plugin example but I could not make it work, I need to retrieve the username,email and gender. If anyone has implemented this before I will appreciate your help.

Thank you

What I have tried:

<script>
var login =function(){
facebookConnectPlugin.login(["email"],
function (response) {
apiTest(response.authResponse.accessToken)
},
function (response) { alert(JSON.stringify(response)) });
}

var apiTest = function (token) {
facebookConnectPlugin.api("me/?
fields=id,name,email,gender&access_token=" +token,
function (response) { alert(response.email + " " +response.name) },
function (response) { alert(JSON.stringify(response)) });
}
</script>
Posted
Updated 2-Oct-17 19:27pm

1 solution

Use the Code




Add these scripts in html page:

JavaScript
<pre><script type="text/javascript" src="angular.js"></script>
<script type="text/javascript" src="ng-cordova.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="app.js"></script>


the body part,

HTML
<body data-ng-app="myApp">
   <div ng-controller="OAuthCtrl">
       <label >
           <button class="button button-block button-positive" 

           ng-click="facebookLogin()">
               Login with Facebook
           </button>
       </label>
   </div>
</body>

and add the following code in app.js file:

JavaScript
var app = angular.module('myApp', ['ngCordova']);

app.controller("OAuthCtrl", function($scope, $cordovaOauth){
    $scope.facebookLogin = function() {

        //user your fb app Id.. 
        $cordovaOauth.facebook(fb_appId, 
        ["email"]).then(function(result) {
            alert(result.access_token);
            // results
        }, function(error) {
            alert("error");
            alert(error);
            // error
        });
    }
})



To Know more: Click Here


Hope it helps. Happy coding!

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900