Community
cancel
Showing results for 
Search instead for 
Did you mean: 
nicolas_r_
Beginner
121 Views

ionic facebook plugin.

Jump to solution

 

Hi im building an apk that need Facebook i make it work the example (whit help of the forum :P) and i also make it work on my other apk but i need to fix some error because the framework that im using (ionic). first of all i need to add a button that login to Facebook. 

 

<button class="button widget uib_w_63 d-margins ion button-positive ion-social-facebook icon-only" data-uib="ionic/button" data-ver="0"></button><button id="login_button" onclick="login();">Login with facebook</button> i try adding the  id="login_button" onclick="login();">Login with Facebook to the ionic button but it does nothing. the other think is i have document.addEventListener("deviceready", function() from the Facebook plugin that din't work on ionic. 

Captura de pantalla 2016-04-04 a las 12.22.10.png

 

 

 

 

Tags (2)
0 Kudos
1 Solution
Diego_Calp
Valued Contributor I
121 Views

Ionic works different, you need to set up a controller to manage the actions.

 

Why don't you use the automatic event handlers provided by XDK?

I did this test:

- Drop a button in a ionic xdk project and put b_login in the ID property.

- Select at the designer right panel, INTERACTIVITY section, the new button, and choose Custom script on the Action drop down.

- This creates this section on index_user_scripts.js file

  $(document).on("click", "#b_login", function(evt)
    {
        /* your code goes here */ 
       login();
    });

I added the login(); line above.

My blue button calls the login function :)

Hope this helps,

 

View solution in original post

6 Replies
Diego_Calp
Valued Contributor I
121 Views

Hi Nicolas,

Is not clear to me. The button is not responding to click and call login() function?

Or it is going to login function and it fails to autenthicate agains FB? If this is the case, will be useful if you post some code.

Regards,

Diego

nicolas_r_
Beginner
121 Views

sorry about the bad english =/. the "login whit Facebook" button works but i want the blue button of Facebook do the same. i copy  id="login_button" onclick="login();" to the blue button but when i click on real device it does nothing.

Diego_Calp
Valued Contributor I
122 Views

Ionic works different, you need to set up a controller to manage the actions.

 

Why don't you use the automatic event handlers provided by XDK?

I did this test:

- Drop a button in a ionic xdk project and put b_login in the ID property.

- Select at the designer right panel, INTERACTIVITY section, the new button, and choose Custom script on the Action drop down.

- This creates this section on index_user_scripts.js file

  $(document).on("click", "#b_login", function(evt)
    {
        /* your code goes here */ 
       login();
    });

I added the login(); line above.

My blue button calls the login function :)

Hope this helps,

 

View solution in original post

nicolas_r_
Beginner
121 Views

you are great man =). from the same form how can i get the data from those input and send whit JSON by ajax?.

Diego_Calp
Valued Contributor I
121 Views

These are two possibilities, you could get them at call moment or inside the login function.

$(document).on("click", "#b_login", function(evt)
​{

      /* your code goes here */
    login($("#email").val(), $("#password").val());
 });

function login(user,pass){

//call the FB login with user and pass values

}

 

Or

 

$(document).on("click", "#b_login", function(evt)
  {
      /* your code goes here */
    login();
 });


function login(user,pass){

//call the FB login with $("#email").val() and $("#password").val()
}

 

nicolas_r_
Beginner
121 Views

sorry for asking to much but i need to first: get into variable the response.first_name, response.last_name etc and then.

var userProfile = function () {

           try{ 
                    facebookConnectPlugin.api( "me/?fields=first_name,last_name,picture", ["public_profile"],
                    function (response) { 
                    //    alert(JSON.stringify(response));
                        $("#profile").html('<h2>'+response.first_name+' '+response.last_name+'</h2><img src="'+response.picture.data.url+'" />');
                        $("#user_button").hide();
    
                    },
                    function (response) { alert(JSON.stringify(response)) }); 
    
              }
    
             catch(err) {
              message.innerHTML = "Input is " + err;
             }
        }

send in this structure.
 $.ajax({
               type: 'post',
               url: 'http://192.168.1.100/api/donante/17512241-9',
               data: {"nombre":$valor,"telefono":$valor},
               dataType: 'json',
                success: function (data) {
                    if(data.result && data.code == 200){
                        console.log("se inserto");    
                        alert('Data Recibida: ' + data);
                    }
                }   
            });

the same for the ionic input. 

 

Reply