0

我正在创建一个应用程序来分享一些东西到 facebook。在这里,当我单击一个按钮时,提要对话框将用于共享,有一个用于添加消息的文本框,我需要从我的代码向文本框发送数据。我怎样才能发送它?

这是我显示提要对话框的代码。

private void showFeedDialog() {
        Bundle postParams = new Bundle();
        postParams.putString("description","message from me ");
        postParams.putString("link", "https://www.google.com");
        WebDialog feedDialog = new WebDialog.FeedDialogBuilder(this, Session.getActiveSession(),postParams)
        .setOnCompleteListener(new OnCompleteListener() {
            @Override
            public void onComplete(Bundle values, FacebookException error) {
                if(error==null)
                {
                    final String postId=values.getString("post_id");
                    if(postId!=null)
                        Toast.makeText(getApplicationContext(), "Posted Successfully", Toast.LENGTH_SHORT).show();
                    else
                        Toast.makeText(getApplicationContext(), "Post canceled", Toast.LENGTH_SHORT).show();
                }
                else
                    if(error instanceof FacebookOperationCanceledException)
                        Toast.makeText(getApplicationContext(), "Publish canceled",Toast.LENGTH_SHORT).show();
                    else
                        Toast.makeText(getApplicationContext(), "connection error", Toast.LENGTH_SHORT).show();
            }
        }).build();
        feedDialog.show();

    }
4

3 回答 3

2

您不能向提要对话框指定用户消息。“名称”、“标题”和“描述”字段仅适用于共享的“链接”。

这是设计使然。

于 2013-08-16T16:28:49.210 回答
0

To post message from activity use this

    Bundle postParams = new Bundle(); 
    postParams.putString("message", "your message");
    postParams.putString("name", "Facebook SDK 3.0 Test By Arshad");
    postParams.putString("caption", "Build great social apps and get more installs.");
    postParams.putString("description",
                    "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
    postParams.putString("link", "https://developers.facebook.com/android");
    postParams.putString("picture",
                    "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
于 2014-11-11T08:12:45.130 回答
0

使用新的 Facebook SDK 3.0 发布 Feed 的代码如下:

// Method for publishing a feed to Facebook
private void publishStory() {
    Session session = Session.getActiveSession();

    Bundle postParams = new Bundle();
    postParams.putString("name", "Facebook SDK 3.0 Test By Arshad");
    postParams.putString("caption", "Build great social apps and get more installs.");
    postParams.putString("description",
                    "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
    postParams.putString("link", "https://developers.facebook.com/android");
    postParams.putString("picture",
                    "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");

    Request.Callback callback = new Request.Callback() {
        public void onCompleted(Response response) {
            Log.i(TAG, "onCompleted FacebookRequest Done");
            JSONObject graphResponse = response.getGraphObject()
                    .getInnerJSONObject();
            try {
                graphResponse.getString("id");
            } catch (JSONException e) {
                Log.i(TAG, "JSON error " + e.getMessage());
            }
            FacebookRequestError error = response.getError();
            if (error != null) {
                Log.i(TAG, "FacebookRequestError" + error.getErrorMessage());
                Toast.makeText(getActivity().getApplicationContext(),
                        error.getErrorMessage(), Toast.LENGTH_SHORT).show();
            } else {
                Log.i(TAG, "FacebookRequest Done");
                Toast.makeText(getActivity().getApplicationContext(),
                        "Story Published to Your Wall", Toast.LENGTH_LONG).show();
            }
        }
    };

    Request request = new Request(session, "me/feed", postParams,
            HttpMethod.POST, callback);

    RequestAsyncTask task = new RequestAsyncTask(request);
    task.execute();
}
于 2013-08-16T04:51:09.337 回答