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

时间:2014-09-04 13:34:39

标签: java android facebook sdk

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

我使用了this facebook tutorial

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

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

3 个答案:

答案 0 :(得分:1)

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

}

答案 1 :(得分:0)

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

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

答案 2 :(得分:0)

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