Check shared Post on Facebook Successfully or discarded - android

Facebook SDK always call onSuccess(Sharer.Result result) after discarding the post.
I am using the share post of the Facebook SDK, but always call onSuccess listener even after the discard or cancel the post.
I am using this facebook SDK for share the post implementation 'com.facebook.android:facebook-share:[4,5)'and use this doc.
https://developers.facebook.com/docs/sharing/android/
shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
#Override
public void onSuccess(Sharer.Result result) {
Log.e(TAG, result.toString());
Toast.makeText(MainActivity.this, "shared succrssfull", Toast.LENGTH_SHORT).show();
}
#Override
public void onCancel() {
Toast.makeText(MainActivity.this, "shared cancel", Toast.LENGTH_SHORT).show();
}
#Override
public void onError(FacebookException error) {
Log.e(TAG, error.toString());
Toast.makeText(MainActivity.this, "shared error occured", Toast.LENGTH_SHORT).show();
}
});
and have onActivity Result is
#Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
but always called onSuccess listner , how can I find the post has been succesfully post.
have checked with multiple link but not got any solution yet so please help me out.
Post Id facebook share dialog always return null in Android
FB share dialog cancel callback not working in Android

we can not recognize the post has been successful or not because the policy has been given by Facebook.
Don't incentivize people to post content on Facebook or give the impression that posting to Facebook will be rewarded. For example, don’t give people anything in exchange for them posting to Facebook (i.e. don’t give or promise virtual goods, achievements, coupons, discounts, access to content or extra entries in a promotion, if they post content to Facebook).
the policy of Facebook has been given below.
https://developers.facebook.com/docs/apps/examples-platform-policy-4.5
https://developers.facebook.com/policy#properuse

Related

How to Retrieve Login Callback from twitter webview using fabric

I am implementing twitter login using fabric, the login with native app seems fine. But when i am trying the login without twitter app installed in the device, it starts authorization with the webview, but on completion i didnt receive any callback neither in onSucccess or failure method
mTwitterAuthClient.authorize(ConnectSocialMedia.this, new Callback<com.twitter.sdk.android.core.TwitterSession>() {
#Override
public void success(Result<com.twitter.sdk.android.core.TwitterSession> result) {
// Success
mDialog.dismiss();
// The TwitterSession is also available through:
// Twitter.getInstance().core.getSessionManager().getActiveSession()
com.twitter.sdk.android.core.TwitterSession session = result.data;
ApplicationData.setSharedPrefValue(mActivity, "twittertoken", session.getAuthToken().token);
ApplicationData.setSharedPrefValue(mActivity, "twittertokensecret", session.getAuthToken().secret);
ApplicationData.setSharedPrefValue(mActivity, "twitterid", String.valueOf(session.getUserId()));
imgTwitter.setVisibility(View.VISIBLE);
mTwitterLoginButton.setEnabled(false);
btnClose.setVisibility(View.VISIBLE);
// getTwitterCover(String.valueOf(session.getUserId()));
}
#Override
public void failure(TwitterException e) {
mDialog.dismiss();
Log.d("TwitterKit", "Login with Twitter failure", e);
Toast.makeText(mActivity, "Twitter Login Failed", Toast.LENGTH_SHORT).show();
mTwitterLoginButton.setEnabled(true);
}
});
}
});
and neither on onActivityResult
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Make sure that the mTwitterLoginButton hears the result from any
// Activity that it triggered.
mTwitterAuthClient.onActivityResult(requestCode, resultCode, data);
}
Please help me, thanks
Add any call back Url in your Twitter app settings page. Every thing will work correctly after that. :)

Is incentivised sharing allowed / possible?

I would like to encourage user engagement in my app by rewarding them with a once off advantage (a kind of power-up I guess) when they share something on social media (twitter, Google+ or Facebook).
My first question is, is this considered acceptable by the Google Play store?
My next question (assuming the answer to my first is yes), is how to be sure the user has completed the share so I do not reward cancelled share intents?
My initial attempt has focussed on Facebook and I have set up the Facebook SDK, registered my App with Facebook and can complete a share, but as others have shown the share result is the same regardless of whether the user cancelled or posted. I note that similar questions have been asked here and here. But none of these have satisfactory solutions.
This answer sounds promising, but I don't recognise the "Session" type as part of the Facebook SDK .
My implementation at the moment uses this in a fragment in response to the user's button press:
if (ShareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("My Title")
.setContentDescription("My Description.")
.setContentUrl(Uri.parse("https://play.google.com/store/apps/details?id=com.cloudforge.svn.bbarrett.floattiles"))
.build();
MainActivity.shareDialog.show(linkContent);
Then in my Main Activity I have the method:
#Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
I note from debug here that "resultCode" is -1 when the user cancels and when they post.
Finally in the MainActivity.onCreate() method I have:
FacebookSdk.sdkInitialize(this.getApplicationContext());
callbackManager = CallbackManager.Factory.create();
shareDialog = new ShareDialog(this);
shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
#Override
public void onSuccess(Sharer.Result result) {
// TODO Auto-generated method stub
if(result.getPostId()!=null){
Toast.makeText(getBaseContext(), "User posted! (but this is never called as postId is always null)", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getBaseContext(), "User didn't post? (but this is called even when they have posted as postId is always null)", Toast.LENGTH_LONG).show();
}
}
#Override
public void onCancel() {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), "User Cancelled (but this is never called)", Toast.LENGTH_LONG).show();
}
#Override
public void onError(FacebookException error) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), "Exception occurred", Toast.LENGTH_LONG).show();
}
});
I dont think my users will be particularly motivated to share unless they gain a game advantage from doing so, so I am really hoping someone can help me confirm a successful Facebook post (I'll deal with Google+ and twitter next!).
Thank you in advance for all reads, upvotes and answers.

Login with extra permission with Facebook SDK 3 for Android

I followed the step of "Create a new Android Project with Facebook Login" section at https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/ The login process is fine. Because I would like to use the native Android button for a user to log in, I modify the code slightly by moving the following code into a View.OnClickListener() of a native Android button. The following is the code in the listener:
Session.openActiveSession(MainActivity.this, true, new Session.StatusCallback() {
// callback when session changes state
#Override
public void call(Session session,SessionState state, Exception exception) {
if (session.isOpened()) {
// make request to the /me API
Request.executeMeRequestAsync(session,new Request.GraphUserCallback() {
// callback after Graph API
// response with user object
#Override
public void onCompleted(GraphUser user,Response response) {
if (user != null) {
Toast.makeText(getApplicationContext(), "Hello " + user.getName() +" "+user.getId()+"!", Toast.LENGTH_LONG).show();
}
}
});
}
}
});
The onActivityResult() and AndroidManifest.xml is the same as the tutorial
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
However, I would like to request get "read_friendlists" when a user logs in successfully. I read the tutorial at https://developers.facebook.com/docs/tutorials/androidsdk/3.0/scrumptious/authenticate/ but it uses Facebook SDK customized button. How can I achieve the same behavior with a native Android button like my code shown above?
I just answered a similar question on another post. My solution allows you to use a native button and request additional read permissions when the user first logs in. Check it out here Ask for more permissions with 3.0 SDK

Android Facebook SDK authorize methods shows dialog every time

I'm writing an Android application that should upload photos to Facebook.
Everything works just fine except one thing. When I called the Facebook.authorize() method for the first time the Facebook dialog was shown with requested permissions and 'Allow'/'Don't Allow' buttons. That was OK. But when I run my app for the secong time I've got the same dialog, but with message that my application allowed already and suggestion to press OK button.
Is there a way to avoid this second dialog? Should I skip the authorize method in some conditions?
I tried to call the Facebook.isSessionValid() method before authorize method, but this did not help.
Here is my simplified code:
mFacebook = new Facebook(APPLICATION_ID);
mFacebookAsync = new AsyncFacebookRunner(mFacebook);
if (mFacebook.isSessionValid()) {
uploadPictureFile();
}
else {
mFacebook.authorize(this, new String[] {"publish_stream"}, new Facebook.DialogListener() {
#Override
public void onFacebookError(FacebookError e) {
Toast.makeText(PhotoFeederFacebookSendActivity.this, "Facebook error: " + e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
finishWithResultCode(RESULT_CANCELED);
}
#Override
public void onError(DialogError e) {
Toast.makeText(PhotoFeederFacebookSendActivity.this, "Facebook dialog error: " + e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
finishWithResultCode(RESULT_CANCELED);
}
#Override
public void onComplete(Bundle values) {
uploadPictureFile();
}
#Override
public void onCancel() {Toast.makeText(PhotoFeederFacebookSendActivity.this, "Facebook authorization cancelled.", Toast.LENGTH_LONG).show();
finishWithResultCode(RESULT_CANCELED);
}
});
}
And here is my onActivityResult method:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
mFacebook.authorizeCallback(requestCode, resultCode, data);
}
Any help appreciated. Thanks.
You need to call mFacebook.setAccessToken("your token") before mFacebook.isSessionValid()
and you need to save the token to preference yourself
If you only intend to update status see my post here...
Android Facebook Graph API to update status

Unable to share Content on Facebook through Android App

I have an android app in which i am using Facebook Android SDK to post content from my application to Facebook Wall. My code was working perfectly till i updated the Facebook app on my phone. Since that time, whenever i try to post content on Facebook, i get the login screen with the "Loading" option and after a few seconds, nothing happens. Here is the code which i am using
On Facebook Button CLick
if(isOnline())
{
mFacebook = new Facebook("APP ID");
mFacebook.authorize(this,new String[] {"publish_stream", "read_stream", "offline_access"}, new AuthorizeListener());
}
The Code for Authorize listener is
class AuthorizeListener implements DialogListener {
public void onComplete(Bundle values) {
// Handle a successful login
postOnWall("My wall text");
}
#Override
public void onCancel() {
}
#Override
public void onError(DialogError e) {
}
#Override
public void onFacebookError(FacebookError e) {
}
}
After debugging i found that the OnComplete method is not being called after calling the authorize function and there is also no exception. This was working perfectly till i update the Facebook app on my Android phone.
Any help will be appreciated
Make sure you are calling Facebook.authorizeCallback in your Activity's onActivityResult:
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
// ... anything else your app does onActivityResult ...
}
For the details, carefully read this page.

Categories

Resources