I want to ask the user of my android app the permission to publish on facebook when a custom share button (it’s just an ImageView) is pressed. On button’s OnClick
method 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 override:
@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 comes: an everlasting spinner wheel is presented and no callback (nor success, nor cancel, nor error) is called.
a. The user is already logged in, according to:
public static boolean isLoggedIn() {
AccessToken accessToken = AccessToken.getCurrentAccessToken();
return accessToken != null;
}
b. FacebookSdk.isInitialized()
is true
c. Publish permissions are not granted, according to:
private static boolean hasPublishPermissions() {
AccessToken accessToken = AccessToken.getCurrentAccessToken();
return accessToken != null && accessToken.getPermissions().contains("publish_actions");
}
d. Other uses of FB SDK are used through the app and they are functioning.
e. I am an app admin on FB dashboard
Any idea on the problem?
Important PS:
Since Facebook’s API is extremely stable, depending on the time of the day or the position of the stars, without changing code I have three possible outcomes:
-
As described before, an everlasting spinner wheel.
-
The callback fires the
onCancel
method without the user interaction. -
It shares the content without asking for confirmation – this gave me a nice unwanted video posted on my personal FB, without me noticing 🙂 –
PS2:
Even the classicLoginManager.getInstance().logInWithReadPermission
now is having the same issue. It never had it before.
2
Answers
I think there is mistake for callback manager.
you declare and assign CallbackManager facebookCallbackManager;
facebookCallbackManager = CallbackManager.Factory.create();
Here you can see there is cbManager instead of facebookCallbackManager
so please double check for that.
then you can share content without everlasting spinner
and getFacebookSharepermission
you can call this function like below