I have tried the Wrapper with facebook installed and everything worked fine: SSO, then publish via custom dialog and everything worked fine.
Then i wanted to do the same on a machine without the facebook app installed, but after the login dialog nothing happened.
Basically, this is the code. I followed basically the code of the sample, so the most of the code should be "familiar":
Fragment fields:
private SimpleFacebook mSimpleFacebook;
private OnLoginListener mOnLoginListener = new OnLoginListener()
{
@Override
public void onThinking()
{
// TODO Auto-generated method stub
toast("Thinking");
}
@Override
public void onException(Throwable throwable)
{
toast("Exception: " + throwable.getMessage());
Log.e(TAG, "Bad thing happened", throwable);
}
@Override
public void onFail(String reason)
{
toast(reason);
}
@Override
public void onLogin()
{
publishFeed();
}
@Override
public void onNotAcceptingPermissions(Type type)
{
toast("Permission not accepted");
}
};
private ProgressDialog mProgress;
Fragment onCreate:
Permission[] permissions = new Permission[]
{
Permission.USER_PHOTOS,
Permission.EMAIL,
Permission.PUBLISH_ACTION
};
SimpleFacebookConfiguration configuration = new SimpleFacebookConfiguration.Builder()
.setAppId(AppConstants.FB_APPID)
.setNamespace(AppConstants.FB_APP_NAMESPACE)
.setPermissions(permissions)
.build();
SimpleFacebook.setConfiguration(configuration);
Fragment onResume as in Sample
Button in Fragment view:
mSimpleFacebook.login(mOnLoginListener);
publishFeed. The Last static function in Utils generates the Feed and the AlertDialog.
private void publishFeed()
{
// listener for publishing action
OnPublishListener onPublishListener = new OnPublishListener()
{
@Override
public void onFail(String reason)
{
hideDialog();
// insure that you are logged in before publishing
Log.w(TAG, "Failed to publish");
// toast("Failed to publish");
}
@Override
public void onException(Throwable throwable)
{
hideDialog();
Log.e(TAG, "Bad thing happened", throwable);
// toast("Bad thing happened");
}
@Override
public void onThinking()
{
// show progress bar or something to the user while publishing
showDialog();
}
@Override
public void onComplete(String postId)
{
hideDialog();
ActionType type = ActionType.FBPOST;
if(MQData.getInstance().checkEventConstraint(mEvent, getActivity().getApplicationContext()))
{
type = ActionType.FBPOSTEVENT;
}
Points.addPoints(type, mEvent.getEvent_id(), getActivity().getApplicationContext());
mActivity.onActionBarChanged(false);
}
};
// feed builder
// Feed feed = new Feed.Builder()
// .setMessage("Clone it out...")
// .setName("Simple Facebook SDK for Android")
// .setCaption("Code less, do the same.")
// .setDescription("The Simple Facebook library project makes the life much easier by coding less code for being able to login, publish feeds and open graph stories, invite friends and more.")
// .setPicture("https://raw.github.com/sromku/android-simple-facebook/master/Refs/android_facebook_sdk_logo.png")
// .setLink("https://github.com/sromku/android-simple-facebook")
// .addAction("Like us on Facebook", "https://www.facebook.com/MuseumsQuartierWien")
// .build();
//
// mSimpleFacebook.publish(feed, true, onPublishListener);
Utils.createFBPostBuilder(mEvent, getActivity(), mSimpleFacebook, onPublishListener).create().show();
}
Is there anything wrong? Do i have to make special configurations in my Facebook App or is it just an error in the Android code?
Thanks in advance,
Lukas
I have found the solution for my problem.
I thought it was sufficient to add onActivityResult in the Fragment
@Override
public void onActivityResult (int requestCode, int resultCode, Intent data)
{
mSimpleFacebook.onActivityResult(getActivity(), requestCode, resultCode, data);
super.onActivityResult(requestCode, resultCode, data);
...
}
but i also had to add this in the activity
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
SimpleFacebook.getInstance(this).onActivityResult(this, requestCode, resultCode, data);
super.onActivityResult(requestCode, resultCode, data);
}