Facebook SDK logInWithPublishPermissions stucks with perpetual counter

I want to ask a user of my Android application to allow sharing on facebook when the user access button is clicked (this is just an ImageView). On the OnClick method button, I execute this block:

 CallbackManager facebookCallbackManager; ... facebookCallbackManager = CallbackManager.Factory.create(); LoginManager.getInstance().registerCallback(facebookCallbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { shareContent(activity, content, true); } @Override public void onCancel() { } @Override public void onError(FacebookException error) { } }); LoginManager.getInstance().logInWithPublishPermissions(activity, Collections.singletonList("publish_actions")); 

And then I redefine:

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

The problem is that the request never arrives: the perpetual wheel of the rotator is displayed, and callbacks are not called (and also are not deleted, are not canceled and no error occurs).

a. The user is already logged in, according to:

 public static boolean isLoggedIn() { AccessToken accessToken = AccessToken.getCurrentAccessToken(); return accessToken != null; } 

b. FacebookSdk.isInitialized() true

with. The publication of permits is not granted, in accordance with:

 private static boolean hasPublishPermissions() { AccessToken accessToken = AccessToken.getCurrentAccessToken(); return accessToken != null && accessToken.getPermissions().contains("publish_actions"); } 

e. Other FB SDK applications are used through the application and they function.

e. I am the application administrator in the FB control panel

Any idea on a problem?

Important PS:

Since the Facebook API is extremely stable, depending on the time of day or the position of the stars, without changing the code I have three possible results :

  • As described above, an ever-rotating wheel.
  • The callback invokes the onCancel method without user interaction.
  • He shares content without asking for confirmation - this gave me a pleasant unwanted video posted on my personal FB, noticing me without :):

    PS2: Even the classic LoginManager.getInstance().logInWithReadPermission now has the same problem. This was not the case before.

+5
source share
2 answers

then you can share content without an eternal spinner

  LoginManager.getInstance().registerCallback(mCallbackManagerFacebook, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { System.out.println("Success"); if (loginResult.getRecentlyGrantedPermissions().contains("publish_actions")) { new shareContent(activity, content, true); } else { //Toast.makeText(youractivity.this, "Successfully Connected to Facebook.", Toast.LENGTH_LONG).show(); GetFacebookPublishPermissions(); } } @Override public void onCancel() { //Log.d(TAG_CANCEL, "On cancel"); LoginManager.getInstance().logOut(); } @Override public void onError(FacebookException error) { Toast.makeText(youractivity.this, "Looks like we are unable to connect to Facebook Servers.", Toast.LENGTH_LONG).show(); LoginManager.getInstance().logOut(); // Log.d(TAG_ERROR, error.toString()); } }); 

and getFacebookSharepermission

  public void GetFacebookPublishPermissions(){ if(LoginManager.getInstance()!=null) { LoginManager.getInstance().logInWithPublishPermissions(youractivity.this, Arrays.asList("publish_actions")); } } 

Update

you can call this function as below

  AccessToken token = com.facebook.AccessToken.getCurrentAccessToken(); if(token!=null) { if (token.getPermissions().contains("publish_actions")) { new shareContent(activity, content, true); }else{ GetFacebookPublishPermissions(); } }else{ LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile", "email", "user_birthday")); } 
+3
source

I think the error is for the callback manager. You declare and assign a CallbackManager facebookCallbackManager; facebookCallbackManager = CallbackManager.Factory.create ();

Here you can see cbManager instead of facebookCallbackManager so please double check this.

  V LoginManager.getInstance().registerCallback(cbManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { shareContent(activity, content, true); } @Override public void onCancel() { } @Override public void onError(FacebookException error) { } }); 
0
source

Source: https://habr.com/ru/post/1272460/


All Articles