0

For the past two days, I have been trying to figure out how to make use of the phonegap-facebook-plugin What I did so far:

  • I created a new phonegap app (phonegap create app --id "com.example.test" --name"app")
  • I cloned the repo and saved it into the app so now my app has a plugin folder that contains the phonegap-facebook-plugin with two platform examples in it (ios and adnroid).
  • I downloaded the phonegap ios app from the app store, started phonegap serve inside the my sample app's www folder (the top www folder - the one you're supposed to be working on), and I can see it running on my phone.

I added the following code to the app's index.js:

onDeviceReady: function() {
  app.receivedEvent('deviceready');
  var fbLoginSuccess = function (userData) {
    alert("UserInfo: " + JSON.stringify(userData));
  }
  facebookConnectPlugin.login(["public_profile"],
    fbLoginSuccess,
    function (error) { alert("" + error) }
  );
},

I added this to my index.html:

<div class="event listening button" onclick="login();">Login with Facebook</div>

When I serve with phonegap, and open on my iphone with the phonegap app, I can see the button LOGIN WITH FACEBOOK. Clicking it doesn't do anything.

Could someone PLEASE create a SIMPLE walkthrough for the installation of this plugin?

Ben
  • 2,957
  • 2
  • 27
  • 55

1 Answers1

1

Remove this Code :

var fbLoginSuccess = function (userData) {
    alert("UserInfo: " + JSON.stringify(userData));
  }
  facebookConnectPlugin.login(["public_profile"],
    fbLoginSuccess,
    function (error) { alert("" + error) }
  );

Added code in bottom of index.js

 function login(){
                   facebookConnectPlugin.login( ["public_profile","email"],function (response) {
                    if(response.authResponse.userID!=''){
                        facebookConnectPlugin.api(response.authResponse.userID+"/?fields=id,email,first_name", ["public_profile"],
                        function (response) {
                            console.log(response);
                        },
                        function (response) {
                            console.log(response);
                        });
                    }    
                    }, 
                    function (response) {   
                            console.log(response);
                   });
                   }

And it will work. Let me know if its not working. Ty example

Kishore Vaishnav
  • 510
  • 3
  • 17