如何使用android中的facebook sdk向feed文件发送消息

时间:2013-08-16 04:19:59

标签: android facebook dialog facebook-android-sdk

我正在创建一个应用程序,用于分享Facebook的内容。在这里,当我点击一个按钮时,将有一个用于共享的提要对话框,有一个用于添加消息的文本框,我需要的是我需要从我的代码向文本框发送数据。我该怎么发送?

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

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

    }

3 个答案:

答案 0 :(得分:2)

您无法为Feed对话框指定用户消息。 “名称”,“标题”和“描述”字段仅适用于正在共享的“链接”。

这是设计的。

答案 1 :(得分: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();
}

答案 2 :(得分:0)

要从活动发布消息,请使用此

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