0

我已经尝试了安装了 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;

片段 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);

片段 onResume 如示例

片段视图中的按钮:

mSimpleFacebook.login(mOnLoginListener);

发布提要。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 应用程序中进行特殊配置,或者这只是 Android 代码中的错误?

提前致谢,

卢卡斯

4

1 回答 1

1

我找到了解决我的问题的方法。

我认为在 Fragment 中添加 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);
}
于 2014-04-11T07:48:44.477 回答