Page 1 of 2

facebook login problem with APK

Posted: Tue Mar 18, 2014 10:46 am
by Mich

I am trying to test the FB app login, starting with the old example posted on Appery:

var cb = null;
if(window.plugins) {
// works only with the native app
cb = window.plugins.childBrowser;
}
if (cb !== null) {etc.etc..

I cannot even get 'window.plugins' to be true (using an android nexus phone) or the appery.io tester.

I am using PG 3.0.0 is my app setup.

Do you have any idea what's going on? Thanks.


facebook login problem with APK

Posted: Tue Mar 18, 2014 1:18 pm
by Nikita

Hello,

Which version of the library do you use?


facebook login problem with APK

Posted: Tue Mar 18, 2014 1:31 pm
by Mich

Hello,

Here is the latest code I am using as I found the newer version of PG doesn't support "window.plugins". I am getting a blank screen somewhere/sometime around the window.open. I have also a window.location.hash = ''" in some generic js.

versions:

v2.0 (originally 1.2)
PG: 3.3.0
jq mobile: 1.4.0
jq 1.9.1

var redirectUrl = encodeURIComponent(pathname);

var url = 'https://www.facebook.com/dialog/oauth...;
url += '&redirect_uri=' + redirectUrl;

url += '&state='+OAuth.nonce(17);

var deviceType = (navigator.userAgent.match(/iPad/i)) == "iPad" ? "iPad" : (navigator.userAgent.match(/iPhone/i)) == "iPhone" ? "iPhone" : (navigator.userAgent.match(/Android/i)) == "Android" ? "Android" : (navigator.userAgent.match(/BlackBerry/i)) == "BlackBerry" ? "BlackBerry" : "desktop";

//localStorage.setItem('deviceType', deviceType);
if (deviceType != 'desktop') {
//alert(url);
var ref = window.open(url, '_blank', 'location=no');
BLANK SCREEN

ref.addEventListener('loadstart', function(event) {
if(event.url.indexOf(redirectUrl) === 0) {
/* if user successfully logged in */
ref.close();
var vars = parseUrlVars(event.url);
localStorage.setItem('code', vars.code);
Appery.navigateTo('startScreen', {reverse: false});
}

});

} else {
localStorage.setItem('code', '');
window.open(url);

// works fine from in non-native mode
}


facebook login problem with APK

Posted: Tue Mar 18, 2014 5:38 pm
by Mich

Any news?


facebook login problem with APK

Posted: Tue Mar 18, 2014 6:06 pm
by Maryna Brodina

Hello!

1) Please take a look here https://getsatisfaction.com/apperyio/...
2) Instead preif (deviceType != 'desktop') /predo preif (typeof cordova !== 'undefined')/pre3) Please note you can call window.open only after device ready event. Otherwise in hybrid app will be opened webView window, ref.addEventListener and ref.close won't work for it.


facebook login problem with APK

Posted: Tue Mar 18, 2014 7:40 pm
by Mich

Hello Maryna.

Same result. I did 2 tests (in the apperyio tester) In both I used the typeof cordova (although my former test with deviceType worked fine I can assure you)

  1. I used a local var ref

  2. I used a global var ref

    In both cases i go through the 1st branch of the test (alert ok1 comes up) and I get a blank screen.

    I had already seen the post you mentionned and my code is based on it.

    Thanks

    var deviceType = (navigator.userAgent.match(/iPad/i)) == "iPad" ? "iPad" : (navigator.userAgent.match(/iPhone/i)) == "iPhone" ? "iPhone" : (navigator.userAgent.match(/Android/i)) == "Android" ? "Android" : (navigator.userAgent.match(/BlackBerry/i)) == "BlackBerry" ? "BlackBerry" : "desktop";

    if (typeof cordova !== 'undefined') {
    //if (deviceType != 'desktop') {
    alert('ok1');

    var ref = window.open(url, '_blank', 'location=no');

    ref.addEventListener('loadstart', function(event) {
    if(event.url.indexOf(redirectUrl) === 0) {
    /* if user successfully logged in */
    ref.close();
    var vars = parseUrlVars(event.url);
    localStorage.setItem('code', vars.code);
    Appery.navigateTo('startScreen', {reverse: false});
    }

    });

    } else {
    localStorage.setItem('code', '');
    window.open(url);
    }


facebook login problem with APK

Posted: Wed Mar 19, 2014 2:06 pm
by Mich

Maryne,

It seems the problem stemmend from the redirect URL. I was using:

var redirect = $(location).attr('href')

instead of pointing back to an http address. I can now get to the fb login. However it seems that the fb login doesn't "stick"... that's the next battle.


facebook login problem with APK

Posted: Wed Mar 19, 2014 4:39 pm
by Maryna Brodina

Hello!
Could you clarify what do you mean on "it seems that the fb login doesn't "stick""? Do you need further help?


facebook login problem with APK

Posted: Wed Mar 19, 2014 4:50 pm
by Mich

I found the way to switch to the web app (non native) with _system. That's waht I am doing now. By not sticking, I mean the following:

  1. the native app now opens correctly a facebook login. However it's not even the fb native app... just the web app. may be that's teh way it's suppose to be.

  2. I log in facebook.

  3. the callback works now that i redirect to an http rather than a file///

  4. However my "FB.Event.subscribe('auth.authResponseChange'" doesn't see I am now connected.

    So far I don't need more help but any comment is welcomed.

    Thanks


facebook login problem with APK

Posted: Thu Mar 20, 2014 7:07 am
by Nikita

Hello,

Most likely, it is related to the fact that you go to another site on the third step.