Facebook SDK for Android 4.1.0 share dialog cancel - android

I'm implementing Facebook sharing feature in my app. I took the code from the example https://developers.facebook.com/docs/sharing/android (Share Dialog)
FacebookCallback is implementing 3 methods onSuccess, onCancel, onError.
shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
#Override
public void onSuccess(Sharer.Result result) {
Timber.e("onSuccess " + result.getPostId());
}
#Override
public void onCancel() {
Timber.e("onCancel");
}
#Override
public void onError(FacebookException e) {
Timber.e("onError");
}
});
I want to know if user cancels share dialog instead of sharing content. But for some reasons onSuccess is called and result.getPostId() is null in both cases if user successfully shares content or cancels dialog. Why onCancel isn't called if user pressed back and why result.getPostId() is null even if post was shared successfully?

You will only get onCancel if the user has authorized your app (i.e. logged into Facebook via your app).
You will only get the postId if your app also has the publish_actions permission.
See https://developers.facebook.com/docs/android/troubleshooting#onsuccess

Related

android snapchat login kit's LoginResultCallback doesn't work normally

I implemented the snapchat login in my Android app by referring to the snapchat login kit sdk guide.
I refer to the below code that uses a custom button.
// Get the login API
SnapLogin snapLogin = SnapLoginProvider.get(getContext());
View yourButtonView = findViewById(...);
yourButtonView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// Start token grant
snapLogin.startTokenGrant(new LoginResultCallback() {
#Override
public void onStart() {
// Here you could update the UI to show login start
}
#Override
public void onSuccess(#NonNull String accessToken) {
// Here you could update the UI to show login success
}
#Override
public void onFailure(#NonNull LoginException exception) {
// Here you could update the UI to show login failure
}
});
}
});
Call startTokenGrant api to complete authentication in snapchat.
After authentication, callback is called when returning to my app.
Step 1 goes well.
But intermittently, the callback is not called.
I thought this was an error in the sdk, but I saw that it works normally in other apps.
Has anyone had an experience where the callback never gets called?
If yes, please help how to solve it.
(I'm developing using dev clientId right now, will this have any effect?)

Using Facebook android SDK ShareDialog. Clicking cross button of sharedialog returning to application with onSuccess callback

I am using Facebook Android SDK version 4.25 and ShareLinkContent, ShareDialog for posting to Facebook on user behalf using my app.
This is the dialog which opens when user clicks my app's share functionality
There are two cross icons in sharedialog as you can see in the image. When i am clicking upper cross icon, sharedialog closes and onCancel callback is called.
Problem is when i am clicking lower cross icon onSuccess callback is being called same when i am clicking Post button. I want to give user some points when he shares post to Facebook. But i am getting success callback on lower cross icon as well. What to do? Thank You.
This is the callback code i am using :-
shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
#Override
public void onSuccess(Sharer.Result result) {
Log.e(LOG_TAG, "Facebook share success " + result.getPostId());
}
#Override
public void onCancel() {
Log.e(LOG_TAG, "Facebook share cancel");
}
#Override
public void onError(FacebookException error) {
Log.e(LOG_TAG, "Facebook share error");
}
});
When you click the upper cross, you are actually closing your own dialog box, that calls onCancel. But when click on the lower cross, it actually is in facebook view. So the callback is returned from facebook not your dialog. Try:
#Override
public void onSuccess(Sharer.Result result) {
Log.e(LOG_TAG, "Facebook share success " + result.getPostId());
//Notice this post id in both, cross click and when the status is updated successfully
//So, if you don't get a valid post id returned, you can count it as a cancel.
}

How to perform action when auth0 Android passwordless auth is completed

trying to implement passwordless auth on android using auth0.
I can get auth0 to add a user/send them an using the below method:
.start(new BaseCallback<Void, AuthenticationException>() {
#Override
public void onSuccess(Void payload) {
}
#Override
public void onFailure(AuthenticationException error) {
}
});
onSuccess() is called if the network request happens successfully (all good).
Once a user clicks on the link in the email, it opens another activity - how can I intercept either a Credentials object, or use onActivityResult() in this activity? The documentation isn't very clear!

How do the App knows whether the user did a Facebook POST or DISCARD

In my Android Game,I am using Facebook SDK to share the open graph story. When the user sees the sharin screen. The user may post it or it can be discarded by pressing the back button.
After the user returs to the game, I need to know whether the user has posted the story or discarded it. I need to reward the user if he shares it.
For now, I use the below code to know the status. The code reaches onSuccess() even for POST or DISCARD.
Code
shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
#Override
public void onSuccess(Sharer.Result result) {
//always gets called
socialShareType=FB_SHARE;
System.out.println("socialShareType in FB onSuccess : " + socialShareType);
Log.d("FBshare", "Share done Successfully");
}
#Override
public void onCancel() {
Log.d("FBshare", "Share cancelled");
}
#Override
public void onError(FacebookException error) {
// TODO Auto-generated method stub
Log.d("FBshare", "Share error");
}
});

Android Facebook LoginButton Callback jumps to canceled

I have the following code. It is a simple test of the callback function of the LoginButton in Facebook's Android API.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_main);
callbackManager = CallbackManager.Factory.create();
LoginButton loginButton = (LoginButton)findViewById(R.id.login_button);
loginButton.setReadPermissions("user_friends");
loginButton.setReadPermissions("email");
loginButton.setReadPermissions("public_profile");
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
Log.e("SUCCESS", "LOGIN SUCCESSFUL");
}
#Override
public void onCancel() {
Log.e("CANCEL", "Cancelled");
}
#Override
public void onError(FacebookException e) {
Log.e("ERROR", "Facebook Exception");
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
The only problem is that whenever I click the loginButton, a dialog appears and disappears for a brief moment, and then the logcat prints out the "CANCEL" text. I cannot seem to fix this error, and I'm not clicking cancel, because that dialog simply shows up and immediately disappears.
Please help me fix this?
As Facebook now requires review of applications which use publish access, you need to log into Facebook Developers Console, in Apps section select your app, click on Roles and add tester (or admin) role.
After this you should be able to get proper access token.
This answer helped me in similar situation.
https://stackoverflow.com/a/31625256/1987045
Call LoginManager.getInstance().logOut(); before attempting a sign in.
I encountered this issue.
It seems to be the case that if you attempt to login (using logInWithReadPermissions or logInWithPublishPermissions) when you already have an access token (with all of the required permissions) then the onCancel callback is executed.
That is to say you should not be logging the user in because the user is already logged in. Check for this first.
My solution:
I had the same problem. The callback was always received by onCancel() method.
I was performing a native login (meaning I was using Facebook App), so after talking with a work-mate, I unistalled my Facebook App to check whether a non-native loging was possible and run my app. To my surprise, before receiving the callback on the onCancel() method, a message informed me my Facebook App ID was wrong, so that was all. I had copied a wrong one instead of the one you get from https://developers.facebook.com/apps.
Now it works and even displays the permissions dialog. What I mean with this is that always try native and non-native. Maybe you get the answer from any of them.
For me this happened because I was calling finish() on my Activity before the Facebook callbacks could complete, causing the activity to finish with RESULT_CANCELED instead of RESULT_OK.
More specifically, my buggy code looked something like this:
#Override
protected void onStart() {
super.onStart();
if (!mAuthRequested) {
mAuthRequested = true;
promptSignIn();
} else {
finish();
}
}
What was happening is that once Facebook's auth activity finishes, onStart() gets called again, but else { finish(); } is invoked before any of Facebook's callbacks are. The fix was to remove the else block.
I hope this helps someone!

Categories

Resources