没有显式登录的Android Facebook SDK 3.0简单状态更新?

时间:2013-04-15 17:01:36

标签: android facebook dialog facebook-login facebook-authentication

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

  1. 如果他们已经登录Facebook,则会出现一个对话框,让他们可以在提交到Facebook之前编辑他们的帖子。

  2. 如果他们尚未登录Facebook,系统将提示您登录,然后在成功登录后自动显示共享对话框。

  3. 是否有一种简单的方法可以执行此操作,还是需要实现单独的Facebook登录流程?

2 个答案:

答案 0 :(得分:3)

所以我认为我有一个非常干净的方法来做到这一点。我欢迎任何评论。

我正在发布我的整个Facebook Manager课程,该课程可以完成登录工作,也可以调出Feed对话框:

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();
    }
}

另外,上面引用的是我的Listener界面,所以我可以通知我与Facebook相关的活动:

public interface ListenerShareFacebook
{
    void onShareFacebookSuccess();

    void onShareFacebookFailure(String error);
}

答案 1 :(得分:2)

我真的推荐这个:

Intent sharingIntent = new Intent(Intent.ACTION_SEND);
         sharingIntent.setType("text/plain");
         sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "text");
         sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Title");
         startActivity(Intent.createChooser(sharingIntent, "Share using"));

这不使用facebook sdk但它确实使用facebook app。在我看来,大多数拥有智能手机和Facebook的人都使用这个应用程序,并期望通过这个应用程序分享一切。 用户也可以点击分享其他内容(推特,短信,g +,电子邮件......)

对我来说,对任何facebook sdk来说都是最好的。 (你也可以附上图片)

相关问题