Android的Facebook的SDK 3.0简单的状态更新没有明确登录? [英] Android Facebook SDK 3.0 Simple Status Update Without Explicit Login?

查看:294
本文介绍了Android的Facebook的SDK 3.0简单的状态更新没有明确登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道更新用户的Facebook状态最简单的方法。我想简单地显示一个分享按钮。当用户触摸分享:

I'd like to know the simplest way to update a user's facebook status. I'd like to simply display a 'Share' button. When the user touches 'Share':

  1. 如果他们已经登录Facebook,将出现一个对话框,让他们在提交给Facebook之前编辑自己的帖子的选项。

  1. If they are already logged in to Facebook, a dialog will appear giving them the option to edit their posting before submitting to Facebook.

如果他们还没有登录到Facebook时,会提示登录,然后自动显示成功登录后共享对话框。

If they aren't already logged in to Facebook, the will be prompted to login and then automatically shown the sharing dialog upon successful login.

有没有一种简单的方法来做到这一点,或者我需要实现一个单独的Facebook登录流量?

Is there a simple way to do this, or do I need to implement a separate facebook login flow?

推荐答案

所以,我认为我已经得到了pretty的干净的方式来做到这一点。我欢迎任何意见。

So I think I've got a pretty clean way to do it. I welcome any comments.

我张贴该做的工作登陆,并以弹出对话框进我的整个Facebook的管理类:

I'm posting my entire Facebook Manager class which does the work to login and also to bring up the feed dialog:

public class ManagerFacebook
{
    private Activity mActivity;

    public void updateStatus(final String name, final String caption, final String description, final String link, final String urlPicture,
        final Activity activity, final ListenerShareFacebook listenerShareFacebook)
    {
        mActivity = activity;

        // start Facebook Login
        Session.openActiveSession(activity, true, new Session.StatusCallback()
        {
            // callback when session changes state
            public void call(final Session session, SessionState state, Exception exception)
            {
                if (session.isOpened())
                {
                    publishFeedDialog(name, caption, description, link, urlPicture, listenerShareFacebook);
                }

            }
        });
    }

    private void publishFeedDialog(String name, String caption, String description, String link, String urlPicture,
        final ListenerShareFacebook listenerShareFacebook)
    {
        Bundle params = new Bundle();
        params.putString("name", name);
        params.putString("caption", caption);
        params.putString("description", description);
        params.putString("link", link);
        params.putString("picture", urlPicture);

        Session session = Session.getActiveSession();

        WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(mActivity, session, params)).setOnCompleteListener(new OnCompleteListener()
        {
            public void onComplete(Bundle values, FacebookException error)
            {
                if (error == null)
                {
                    // When the story is posted, echo the success
                    // and the post Id.
                    final String postId = values.getString("post_id");
                    if (postId != null)
                    {
                        listenerShareFacebook.onShareFacebookSuccess();
                    }
                    else
                    {
                        // User clicked the Cancel button
                        listenerShareFacebook.onShareFacebookFailure("Publish cancelled");
                    }
                }
                else if (error instanceof FacebookOperationCanceledException)
                {
                    // User clicked the "x" button
                    listenerShareFacebook.onShareFacebookFailure("Publish cancelled");
                }
                else
                {
                    // Generic, ex: network error
                    listenerShareFacebook.onShareFacebookFailure("Error posting story");
                }
            }

        }).build();
        feedDialog.show();
    }
}

另外,上面提到的是我的监听器接口,这样我就可以通知我的Facebook的相关东西的活动:

Also, referenced above is my Listener interface so I can notify my Activity of Facebook related stuff:

public interface ListenerShareFacebook
{
    void onShareFacebookSuccess();

    void onShareFacebookFailure(String error);
}

这篇关于Android的Facebook的SDK 3.0简单的状态更新没有明确登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆