通过facebook sdk分享自定义TEXT状态

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通过facebook sdk分享自定义TEXT状态相关的知识,希望对你有一定的参考价值。

我想在我的android应用程序中使用facebook sdk分享自定义文本状态。

我用过this facebook tutorial

FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(MainActivity.this)
                .setLink("https://developers.facebook.com/android")
                .build();
                uiHelper.trackPendingDialogCall(shareDialog.present());

但我如何分享文字(不是链接)?

答案

通过使用FacebookDialog(Facebook API),您无法以编程方式添加消息

另一答案
private void publishFeedDialog() {
Bundle params = new Bundle();
params.putString("name", "Facebook SDK for Android");
params.putString("caption", "Build great social apps and get more installs.");
params.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
params.putString("link", "https://developers.facebook.com/android");
params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");

WebDialog feedDialog = (
    new WebDialog.FeedDialogBuilder(getActivity(),
        Session.getActiveSession(),
        params))
    .setOnCompleteListener(new OnCompleteListener() {

        @Override
        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) {
                    Toast.makeText(getActivity(),
                        "Posted story, id: "+postId,
                        Toast.LENGTH_SHORT).show();
                } else {
                    // User clicked the Cancel button
                    Toast.makeText(getActivity().getApplicationContext(), 
                        "Publish cancelled", 
                        Toast.LENGTH_SHORT).show();
                }
            } else if (error instanceof FacebookOperationCanceledException) {
                // User clicked the "x" button
                Toast.makeText(getActivity().getApplicationContext(), 
                    "Publish cancelled", 
                    Toast.LENGTH_SHORT).show();
            } else {
                // Generic, ex: network error
                Toast.makeText(getActivity().getApplicationContext(), 
                    "Error posting story", 
                    Toast.LENGTH_SHORT).show();
            }
        }

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

}

另一答案

试试这种方式,希望这可以帮助您解决问题。

 private FacebookDialog.ShareDialogBuilder createShareDialogBuilderForLink() {
            return new FacebookDialog.ShareDialogBuilder(mActivity)
            .setName(mTitle)
            .setDescription(mDescription)
            .setLink(mUrlShare);
        }

以上是关于通过facebook sdk分享自定义TEXT状态的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Facebook SDK 中创建自定义分享按钮

如何在没有 SDK 或自定义应用程序 ID 的情况下创建 Facebook 分享按钮?

Facebook javascript SDK 分享图片问题

使用 javascript SDK 自定义皮肤 facebook like 按钮

Facebook 分享按钮 - 自定义图片

Android Facebook sdk 覆盖登录按钮