Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - facebook sdk Login window disappear

I am trying to use the Android Facebook SDK - but with no luck. The problem is that the Facebook Login window starts loading, but before anything happens it disappears. This is the behaviour on an actual device, on the emulator all is good.

What I have done:

  1. downloaded the SDk from here
  2. added the java files to my project.
  3. created a facebook application.
  4. Got the Key Hash value and updated my facebook app.

But I cant get the Login window to appear. I dont see any error on the logcat, only this:

ActivityManager( 2698): Starting: Intent { cmp=com.facebook.katana/.ProxyAuth (has extras) ActivityManager( 2698): Trying to launch com.facebook.katana/.ProxyAuth ActivityManager( 2698): Displayed com.facebook.katana/.ProxyAuth: +371ms (total +466ms)

Any ideas?

10X :)

EDIT: It seems adding these lines of code to the activity solved the problem:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    facebook.authorizeCallback(requestCode, resultCode, data);
}

Got if from here: SO Question

like image 531
Udi Idan Avatar asked Oct 09 '22 01:10

Udi Idan


2 Answers

That logcat error from com.facebook.katana is from the Android Facebook app. Is that installed on the phone? It sounds like it is and you are defaulting to Single Sign On (SSO)? Try doing your authorize as

authorize(this, PERMISSIONS, FORCE_DIALOG_AUTH, new LoginDialogListener());

which avoids SSO and forces a dialog login. If that circumvents your crash, then the most likely cause is a mismatch between the SDK and the installed Facebook app. They do tend to be quite picky about working together. If so, you'll probably have to try several different versions of each before you find a stable pair.

like image 171
Torid Avatar answered Oct 13 '22 10:10

Torid


Do you already install on device native application facebook? Because com.facebook.katana - this is from facebook application. It could happen, because already auth by this application. What I do? I comments in facebook.java code:

    public void authorize(Activity activity, String[] permissions, int activityCode, final      DialogListener listener) {
    boolean singleSignOnStarted = false;

    mAuthDialogListener = listener;

    // Prefer single sign-on, where available.
    //      if (activityCode >= 0) {
    //          singleSignOnStarted = startSingleSignOn(activity, mAppId, permissions, activityCode);
    //      }
    // Otherwise fall back to traditional dialog.
    if (!singleSignOnStarted) {
        startDialogAuth(activity, permissions);
    }
}

Also I try do multi login and find problem, when I auth with one login/password, try add new login, show facebook dialog and in browser auto page login show and immediately disappears. Because occurred login with previos data. When I in facebook.java: disable in startDialogAuth cookies.

    private void startDialogAuth(Activity activity, String[] permissions) {
    Bundle params = new Bundle();

    if (permissions.length > 0) {
        params.putString("scope", TextUtils.join(",", permissions));
    }
    //      CookieSyncManager.createInstance(activity);
    Util.clearCookies(activity);

    dialog(activity, LOGIN, params, new DialogListener() {

        public void onComplete(Bundle values) {
            // ensure any cookies set by the dialog are saved
            //              CookieSyncManager.getInstance().sync();
            setAccessToken(values.getString(TOKEN));
            setAccessExpiresIn(values.getString(EXPIRES));
            if (isSessionValid()) {
                Tracks.itTrack(Tracks.Dev, "Facebook-authorize. Login Success! access_token=%s  expires=%s", getAccessToken(), getAccessExpires());
                mAuthDialogListener.onComplete(values);
            }
            else
                mAuthDialogListener.onFacebookError(new FacebookError("Failed to receive access token."));
        }

        public void onError(DialogError error) {
            Tracks.itTrack(Tracks.Dev, "Facebook-authorize. Login failed: %s", error);
            mAuthDialogListener.onError(error);
        }

        public void onFacebookError(FacebookError error) {
            Tracks.itTrack(Tracks.Dev, "Facebook-authorize. Login failed: %s", error);
            mAuthDialogListener.onFacebookError(error);
        }

        public void onCancel() {
            Tracks.itTrack(Tracks.Dev, "Facebook-authorize. Login canceled");
            mAuthDialogListener.onCancel();
        }
    });
}
like image 27
Yura Shinkarev Avatar answered Oct 13 '22 12:10

Yura Shinkarev