Mich
Posts: 0
Joined: Sat Feb 08, 2014 3:38 pm

facebook login problem with APK

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.

Nikita
Posts: 0
Joined: Fri Feb 28, 2014 4:02 pm

facebook login problem with APK

Hello,

Which version of the library do you use?

Mich
Posts: 0
Joined: Sat Feb 08, 2014 3:38 pm

facebook login problem with APK

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
}

Mich
Posts: 0
Joined: Sat Feb 08, 2014 3:38 pm

facebook login problem with APK

Any news?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

facebook login problem with APK

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.

Mich
Posts: 0
Joined: Sat Feb 08, 2014 3:38 pm

facebook login problem with APK

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);
    }

Mich
Posts: 0
Joined: Sat Feb 08, 2014 3:38 pm

facebook login problem with APK

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.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

facebook login problem with APK

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

Mich
Posts: 0
Joined: Sat Feb 08, 2014 3:38 pm

facebook login problem with APK

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

Nikita
Posts: 0
Joined: Fri Feb 28, 2014 4:02 pm

facebook login problem with APK

Hello,

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

Return to “Issues”