Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facebook android does not call callback function upon login #29

Open
Ayame opened this issue Mar 12, 2013 · 2 comments
Open

Facebook android does not call callback function upon login #29

Ayame opened this issue Mar 12, 2013 · 2 comments

Comments

@Ayame
Copy link

Ayame commented Mar 12, 2013

I have a strange error with your plugin, the biggest problem being there are not errors generated.

The situation is as follows:

  • When the user clicks login in my application, I call the FB.login() function and he is redirected to either the facebook app if installed or the web browser if not installed
  • When using the web browser to login, everything works fine, user credentials are returned and the app usage can continue
  • When the user has the facebook app installed however, after providing credentials the app switches back to my app, but does not call the callback function for the login. It's as if nothing happens.

The other odd thing is that the code I use works on iOS in both cases.

The code I use:

FB.login(
function(response) { console.log("RESPONSE FROM LOGIN");
if (response.authResponse) {
// some code here
} else {
alert('An error has occurred');
}
},
{ scope: "email" }
);

before this I call:

FB.init({ appId: myappid, status: true,
cookie: true,
xfbml: true,
oauth: true,
nativeInterface: CDV.FB,
useCachedDialogs: false
});

The logger returns:
03-12 22:51:28.470: D/CordovaLog(21023): Cordova Facebook Connect plugin initialized successfully.
03-12 22:51:28.470: D/CordovaLog(21023): : Line 1192040477 : Cordova Facebook Connect plugin initialized successfully.

All I get from the moment I call the FB.login() function until it returns me to the app is:
03-12 22:58:45.170: D/DroidGap(21023): Paused the application!
03-12 22:58:45.170: D/CordovaWebView(21023): Handle the pause
03-12 22:58:45.170: D/CordovaWebView(21023): >>> loadUrlNow()
03-12 22:58:47.115: D/dalvikvm(21023): GC_CONCURRENT freed 349K, 50% free 3206K/6407K, external 408K/892K, paused 2ms+8ms
03-12 22:58:47.175: D/CLIPBOARD(21023): Hide Clipboard dialog at Starting input: finished by someone else... !
03-12 22:58:49.715: D/DroidGap(21023): Resuming the App
03-12 22:58:49.715: D/CordovaWebView(21023): >>> loadUrlNow()

I'm really puzzled with this issue as it does work in the web view and on iOS; I would like to keep the source the same for iOS and android so I hope someone can help me resolve this issue.

Thanks!

@Ayame
Copy link
Author

Ayame commented Mar 13, 2013

Perhaps a follow up on this with an isolated example: I get the same problem with the sample "Simple" application.

I work with cordova 2.1.0 so according to the docs it should work. It appears that the FB.login() callback function is never called. I see the "will login" console.log, but not the "RESPONSE" console.log when the app uses the native FB app to connect on the system.
I have tested this on several devices with different android versions and keep getting the same result.

Any help would be wonderful.

For the sake of reference I have pasted the code below. Naturally I have replaced the appid with myappid here, please replace it with yours.

<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
        <button onclick="login()">Login</button>
        <button onclick="me()">Me</button>
        <!--<button onclick="getSession()">Get session</button>-->
        <button onclick="getLoginStatus()">Get login</button>
        <button onclick="logout()">Logout</button>
        <button onclick="facebookWallPost()">facebookWallPost</button>
        <button onclick="publishStoryFriend()">friendstory</button>

        <div id="data">loading ...</div>
        <!--<script src="http://localhost:8080/target/target-script-min.js#anonymous"></script>-->
        <div id="fb-root"></div>
        <!-- cordova -->
        <script src="cordova-2.1.0.js"></script>
        <!-- cordova facebook plugin -->
        <script src="cdv-plugin-fb-connect.js"></script>
        <!-- facebook js sdk -->
        <script src="facebook_js_sdk.js"></script>

        <script>

            if ((typeof cordova == 'undefined') && (typeof Cordova == 'undefined')) alert('Cordova variable does not exist. Check that you have included cordova.js correctly');
            if (typeof CDV == 'undefined') alert('CDV variable does not exist. Check that you have included cdv-plugin-fb-connect.js correctly');
            if (typeof FB == 'undefined') alert('FB variable does not exist. Check that you have included the Facebook JS SDK file.');

            FB.Event.subscribe('auth.login', function(response) {
                               alert('auth.login event');
                               });

            FB.Event.subscribe('auth.logout', function(response) {
                               alert('auth.logout event');
                               });

            FB.Event.subscribe('auth.sessionChange', function(response) {
                               alert('auth.sessionChange event');
                               });

            FB.Event.subscribe('auth.statusChange', function(response) {
                               alert('auth.statusChange event');
                               });

            /*function getSession() {
                alert("session: " + JSON.stringify(FB.getSession()));
            }
            */
            function getLoginStatus() {
                FB.getLoginStatus(function(response) {
                                  if (response.status == 'connected') {
                                  alert('logged in');
                                  } else {
                                  alert('not logged in');
                                  }
                                  });
            }
            var friendIDs = [];
            var fdata;
            function me() {
                FB.api('/me/friends', { fields: 'id, name, picture' },  function(response) {
                       if (response.error) {
                       alert(JSON.stringify(response.error));
                       } else {
                       var data = document.getElementById('data');
                       fdata=response.data;
                       console.log("fdata: "+fdata);
                       response.data.forEach(function(item) {
                                             var d = document.createElement('div');
                                             d.innerHTML = "<img src="+item.picture+"/>"+item.name;
                                             data.appendChild(d);
                                             });
                       }
                    var friends = response.data;
                    console.log(friends.length); 
                    for (var k = 0; k < friends.length && k < 200; k++) {
                        var friend = friends[k];
                        var index = 1;

                        friendIDs[k] = friend.id;
                        //friendsInfo[k] = friend;
                    }
                    console.log("friendId's: "+friendIDs);
                       });
            }

            function logout() {
                FB.logout(function(response) {
                          alert('logged out');
                          });
            }

            function login() { console.log("will login")
                FB.login(
                         function(response) {
                         console.log('RESPONSE'); 
                         console.log(response.authResponse);
                         if (response.session) {
                         alert('logged in');
                         } else {
                         alert('not logged in');
                         }
                         },
                         { scope: "email" }
                         );
            }


            function facebookWallPost() {
                console.log('Debug 1');
                var params = {
                    method: 'feed',
                    name: 'Facebook Dialogs',
                    link: 'https://developers.facebook.com/docs/reference/dialogs/',
                    picture: 'http://fbrell.com/f8.jpg',
                    caption: 'Reference Documentation',
                    description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
                  };
                console.log(params);
                FB.ui(params, function(obj) { console.log(obj);});
            }

            function publishStoryFriend() {
                randNum = Math.floor ( Math.random() * friendIDs.length ); 

                var friendID = friendIDs[randNum];
                if (friendID == undefined){
                    alert('please click the me button to get a list of friends first');
                }else{
                    console.log("friend id: " + friendID );
                    console.log('Opening a dialog for friendID: ', friendID);
                    var params = {
                        method: 'feed',
                        to: friendID.toString(),
                        name: 'Facebook Dialogs',
                        link: 'https://developers.facebook.com/docs/reference/dialogs/',
                        picture: 'http://fbrell.com/f8.jpg',
                        caption: 'Reference Documentation',
                        description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
                    };
                    FB.ui(params, function(obj) { console.log(obj);});
                }
            }

            document.addEventListener('deviceready', function() {
                                      try {
                                      alert('Device is ready! Make sure you set your app_id below this alert.');
                                      FB.init({ appId: "myappid", nativeInterface: CDV.FB, useCachedDialogs: false });
                                      document.getElementById('data').innerHTML = "";
                                      } catch (e) {
                                      alert(e);
                                      }
                                      }, false);
            </script>
        <div id="log"></div>
    </body>
</html>

@jramoseguinoa
Copy link

I had this same problem (callback not being triggered) when trying to login using the Facebook app. In my case the problem was the key hash I've generated with Java's keytool (I was using a wrong version of openssl). I used the instructions in this link to generate the correct key hash: http://stackoverflow.com/a/6665263

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants