Android: Facebook always shows that you have already authorized the application dialog

I use Facebook SDK 4.1.2 and testing on Android 4.4.2 - I know that I have a Facebook application that has been removed from my mobile phone for testing, which means that the system logs in and authorizes my application through web browsing, provided by the FB SDK.

I get this message in the dialog box every time I clear the memory "You have already resolved {Application Name}"

How to avoid the repeated appearance of this message, which can ruin the user's work?

Knowing this and based on the code below, every time I clear my mobile memory, AccessToken.getCurrentAccessToken () returns null when the application starts, which leads in my code to run two lines below, which, I believe, is responsible for this message.

List<String> PUBLIC_PROFILE_PERMISSION = Arrays.asList("public_profile"); LoginManager.getInstance().logInWithReadPermissions(this, PUBLIC_PROFILE_PERMISSION); //Log in to FB 

My entry is in the code stream and please submit if it can be improved:

 AccessToken mAccessToken; CallbackManager callbackManager; AccessTokenTracker accessTokenTracker; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); FacebookSdk.sdkInitialize(this); callbackManager = CallbackManager.Factory.create(); updateWithToken(AccessToken.getCurrentAccessToken()); accessTokenTracker = new AccessTokenTracker() { @Override protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken newAccessToken) { updateWithToken(newAccessToken); } }; } 

// function updateWithToken (...)

 private void updateWithToken(AccessToken currentAccessToken) { if (currentAccessToken != null) { mAccessToken = currentAccessToken; AccessToken.setCurrentAccessToken(currentAccessToken); } else { LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { // App code mAccessToken = loginResult.getAccessToken(); AccessToken.setCurrentAccessToken(mAccessToken); } @Override public void onCancel() { // App code } @Override public void onError(FacebookException exception) { Log.d("", ""); } }); List<String> PUBLIC_PROFILE_PERMISSION = Arrays.asList("public_profile"); // public_profile LoginManager.getInstance().logInWithReadPermissions(this, PUBLIC_PROFILE_PERMISSION); //Log in to FB } } 

// function onDestroy ()

 @Override public void onDestroy() { super.onDestroy(); accessTokenTracker.stopTracking(); } 

// function onActivityResult (...)

 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); callbackManager.onActivityResult(requestCode, resultCode, data); } 
+5
source share
1 answer

I used this post when in onSucesss () I registered as follows:

The code

  GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(JSONObject object, GraphResponse response) { try { String s = object.getString("first_name") + " " + object.getString("last_name"); inputName.setText(s); inputEmail.setText(object.getString("email")); } catch (Exception e) { } } }).executeAsync(); } 

But then I changed the last line as follows:

Code after editing

  Bundle parameters = new Bundle(); parameters.putString("fields", "id, first_name, last_name, email"); // parameters to get from facebook request.setParameters(parameters); request.executeAsync(); 

and this message has disappeared.

EDIT 2

However, I only found out that after leaving Facebook using

  LoginManager.getInstance().logOut(); 

and then log back in, the message returned. But until I quit the program programmatically, and instead I pressed the Facebook exit button (after I started the message on the button, it changed to "Log Out"), this message did not appear.

EDIT 3

The final solution to the problem is to remove the permission before logging out, as shown below (replace the FBuserID variable with the actual user ID that you got from facebook using loginResult.getAccessToken (). GetUserId ():

 private void logOut(){ GraphRequest delPermRequest = new GraphRequest(AccessToken.getCurrentAccessToken(), "/" + FBuserID + "/permissions/", null, HttpMethod.DELETE, new GraphRequest.Callback() { @Override public void onCompleted(GraphResponse graphResponse) { if (graphResponse != null){ FacebookRequestError error = graphResponse.getError(); if (error != null) // error else // SUCCESS } } }); delPermRequest.executeAsync(); LoginManager.getInstance().logOut(); } 
+1
source

All Articles