SDK sends wrong key so login fails with invalid key if facebook app is installed

I created keys from my debug keystore as well as my keystore and set them as in the "Main Android App" field for the facebook app.

I've tested this on multiple devices and it always works with debug.keystore (when deploying from eclipse). But when I sign the app package with my keystore, it only works if the facebook app is not installed on the device.

If the facebook app is installed, it sends a different key which I don't know.

I generated the hash key very carefully by assigning the correct path and password as explained in the instructions from Facebook.

Note. When working with debug.keystore, it works, but it seems to be using the auth dialog and not the facebook app.

thank

public void share(final int score) {        
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            try {
                mScoreToShare = score;

                if (mGLView != null)
                    mGLView.stopDrawing(); 

                getFacebook();

                if(!mFacebook.isSessionValid()) {
                    facebookAuthorize();    
                }
                else {
                    facebookShowFeedDialog();
                }
            } catch (Exception e) {
                Log.error("Share failed", e);

                if (mGLView != null)
                    mGLView.startDrawing();
            }
        }
    });     
}

private Facebook getFacebook() {

    if (mFacebook == null) {

        mFacebook = new Facebook("xxx");

        SharedPreferences prefs = getSharedPreferences("xxx", MODE_PRIVATE);//getPreferences(MODE_PRIVATE);

        String access_token = prefs.getString("access_token", null);
        long expires = prefs.getLong("access_expires", 0);

        if(access_token != null) {
            mFacebook.setAccessToken(access_token);
        }

        if(expires != 0) {
            mFacebook.setAccessExpires(expires);
        }
    }

    return mFacebook;
}

private void facebookAuthorize() {

    //mFacebook.authorize(this, null, Facebook.FORCE_DIALOG_AUTH, new DialogListener() {
    mFacebook.authorize(this, new DialogListener() {
        @Override
        public void onComplete(Bundle values) {

            SharedPreferences.Editor editor = getSharedPreferences("xxx", MODE_PRIVATE).edit();
            editor.putString("access_token", mFacebook.getAccessToken());
            editor.putLong("access_expires", mFacebook.getAccessExpires());
            editor.commit();

            facebookShowFeedDialog();
        }

        @Override
        public void onFacebookError(FacebookError error) {
            mFacebook = null;
            showAlert();                
            if (mGLView != null)
                mGLView.startDrawing();
        }

        @Override
        public void onError(DialogError e) {
            mFacebook = null;
            showAlert();                
            if (mGLView != null)
                mGLView.startDrawing();
        }

        @Override
        public void onCancel() {
            mFacebook = null;
            if (mGLView != null)
                mGLView.startDrawing();
        }
    });     
}

private void facebookExtendAccessTokenIfNeeded() {
    if (mFacebook != null) {
        mFacebook.extendAccessTokenIfNeeded(this, null);
    }
}

private void facebookShowFeedDialog() {

    Bundle parameters = new Bundle();

    String caption = "";

    parameters.putString("caption", caption);
    parameters.putString("description", "");
    parameters.putString("picture", "");

    //post on user wall.
    mFacebook.dialog(this, "feed", parameters, new DialogListener(){
        @Override
        public void onComplete(Bundle values) {     
            mFacebook = null;               
            if (mGLView != null)
                mGLView.startDrawing();
        }

        @Override
        public void onFacebookError(FacebookError error) {
            mFacebook = null;
            showAlert("");              
            if (mGLView != null)
                mGLView.startDrawing();
        }

        @Override
        public void onError(DialogError e) {
            mFacebook = null;
            showAlert("");              
            if (mGLView != null)
                mGLView.startDrawing();
        }

        @Override
        public void onCancel() {
            mFacebook = null;
            if (mGLView != null)
                mGLView.startDrawing();
        }
    });

}

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

    if (mFacebook != null) {
        mFacebook.authorizeCallback(requestCode, resultCode, data); 
    }
}

      

+3


source to share


1 answer


Delete the app from facebook and re-create it with the same hash key.



0


source







All Articles