How to avoid already-authorized in Android Facebook SDK

后端 未结 5 853
无人共我
无人共我 2020-12-08 14:17

I\'m getting a completely useless page when I use the Single Sign on for Facebook\'s Android SDK.

\"You have already authorized happyapp. Press \"O

5条回答
  •  不思量自难忘°
    2020-12-08 14:44

    I ran into this issue after any device had authorized my app with facebook. My emulator continued to work perfectly but I could not get the phone to get past the "okay" dialog screen and do anything meaningful. I added the facebook.FORCE_DIALOG_AUTH parameter to the authorize() call. Now it asks me to login once per device and sets the TOKEN and expiration in shared preferences as it should.

    Button button_facebook = (Button) findViewById(R.id.button_share_on_facebook);
    button_facebook.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {
            if (access_token != null) {
                facebook.setAccessToken(access_token);
            }
    
            if (expires != 0) {
                facebook.setAccessExpires(expires);
            }
    
            if (!facebook.isSessionValid()) {
                facebook.authorize(YourActivity.this, new String[] { "user_photos,publish_checkins,publish_actions,publish_stream" }, facebook.FORCE_DIALOG_AUTH, new DialogListener() {
                    @Override
                    public void onComplete(Bundle values) {
                        SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                        SharedPreferences.Editor editor = mPrefs.edit();
                        editor.putString("access_token", facebook.getAccessToken());
                        editor.putLong("access_expires", facebook.getAccessExpires());
                        editor.commit();
                        postSomethingToFacebook();
                    }
    
                    @Override
                    public void onFacebookError(FacebookError e) {
                        Log.e("Facebook-Authorize", "FacebookError Error: " + e.getMessage());
                    }
    
                    @Override
                    public void onError(DialogError e) {
                        Log.e("Facebook-Authorize", "DialogError Error: "   + e.getMessage());
                    }
    
                    @Override
                    public void onCancel() {
                        Log.w("Facebook-Authorize", "Cancelled.");
                    }
                });
            } else {
                postSomethingToFacebook();
            }
    });
    

提交回复
热议问题