我尝试了安装了facebook的Wrapper,一切都很好:SSO,然后通过自定义对话框发布,一切都正常。
然后我想在没有安装facebook应用程序的机器上做同样的事情,但在登录对话框后什么也没发生。
基本上,这就是代码。我基本上遵循了样本的代码,所以大部分代码应该是"熟悉的":
片段字段:
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;
创建片段:
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);
恢复中的片段与样本中的片段相同
片段视图中的按钮:
mSimpleFacebook.login(mOnLoginListener);
publishFeed。Utils中的Last静态函数生成Feed和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();
}
有什么问题吗?我必须在我的Facebook应用程序中进行特殊配置吗?还是这只是安卓代码中的一个错误?
提前感谢
卢卡斯
我已经找到了问题的解决方案。
我认为在片段中添加onActivityResult就足够了
@Override
public void onActivityResult (int requestCode, int resultCode, Intent data)
{
mSimpleFacebook.onActivityResult(getActivity(), requestCode, resultCode, data);
super.onActivityResult(requestCode, resultCode, data);
...
}
但我也不得不在活动中添加这个
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
SimpleFacebook.getInstance(this).onActivityResult(this, requestCode, resultCode, data);
super.onActivityResult(requestCode, resultCode, data);
}