简体   繁体   English

facebook sdk android墙贴线休息

[英]facebook sdk android wall post line break

I'm making an application that is posting some information to your facebook wall using facebook sdk for android. 我正在制作一个应用程序,使用facebook sdk for android将一些信息发布到你的Facebook墙上。 This works, but I can't seem to get new lines on the posts. 这样可行,但我似乎无法在帖子上获得新的内容。 I have tried \\n but it doesent work. 我曾尝试\\n但doesent工作。 Any suggestions? 有什么建议么?

Here is my code: 这是我的代码:

Bundle parameters = new Bundle();

String temp = "";
for (int i = 0; i < mArrayAdapter.getCount(); i++){
            temp = temp + mArrayAdapter.getItem(i) + "\n"; // Not working
}

parameters.putString("message", temp);
mFacebook.dialog(this, "stream.publish", parameters, new DialogListener());  

Thanks, 谢谢,

James Ford 詹姆斯福特

Hi James i have tried that before, even with html code but i think thats not possible. 嗨詹姆斯我以前尝试过,即使使用HTML代码,但我认为这是不可能的。 The reason, Facebook must have a control to avoid blank spaces or line break on his posts. 原因是,Facebook必须有一个控制权来避免他的帖子上出现空格或换行。

流帖子中不允许使用新行(过去你可能已经看过它们的是facebook上的错误)。

This worked for me: 这对我有用:

StringBuilder messageData = new StringBuilder(title).append('\n')
    .append('\n').append(message).append('\n').append('\n')
    .append(description);
// Message
postParams.putString("message", messageData.toString());

make use of JSON to post on facebook.. how? 利用JSON在facebook上发帖..怎么样? look here 看这里

STEPS :- 脚步 :-

Step 1 :- At this link u will came to know how to use JSON for setting text to TEXTVIEW. 第1步: - 在此链接中,您将了解如何使用JSON将文本设置为TEXTVIEW。

Step 2 :- May be this is not ur looking for :) assign the text of textview to some string using GetText().ToString 第2步: - 可能这不是你在寻找:)使用GetText().ToString将textview的文本分配给某些字符串GetText().ToString

Step 3 :- use this string to post to the facebook. 第3步: - 使用此字符串发布到Facebook。

Step 4 :- I did the same after spending lot of time in googling and finally got the result by using this trick. 第4步: - 我在google搜索后花了很多时间做了同样的事情,最后通过使用这个技巧获得了结果。 u can see my post that i posted during test here ü可以看到我的帖子,我测试期间张贴在这里

Step 5 :- set the visibilty of this text box to gone using 第5步: - 将此文本框的可见性设置为不再使用

tv.setVisibility(View.GONE)

And ur done with your posting to facebook.. let the facebook and textview handle how they manage spaces and new line character :D 你完成了你的发布到Facebook ..让facebook和textview处理他们如何管理空格和新线字符:D

Some Coding work for newbies like me... 一些编码为像我这样的新手工作......

I am posting it on click of button 我点击按钮发布它

1) 1)

 tv= (TextView)findViewById(R.id.tv);
 click=(Button)findViewById(R.id.btn1);
    click.setOnClickListener(mthdpost);

2) add on click event to this button 2)将click事件添加到此按钮

   private View.OnClickListener mthdpost=new View.OnClickListener() {

        @Override
        public void onClick(View v) {
try {
                String json = "{"

                    + "  \"name\": \"myName\", "

                    + "  \"message\": [\"myMessage1\",\"myMessage2\"],"

                    + "  \"place\": \"myPlace\", "

                    + "  \"date\": \"thisDate\" "

                    + "}";

                /* Create a JSON object and parse the required values */

                JSONObject object = (JSONObject) new JSONTokener(json).nextValue();

                String name = object.getString("name");

                String place = object.getString("place");

                String date = object.getString("date");

                JSONArray message = object.getJSONArray("message");

                String MessageToPost= null;
                tv.setText("Name: "+ name +"\n\n");

                tv.append("Place: "+ place +"\n\n");

                tv.append("Date: "+ date +"\n\n");



                /*JSONObject attachment = new JSONObject();

                attachment.put("Name: ","\n\n");

                attachment.put("Place: ","\n\n");

                attachment.put("Date: ","\n\n");*/

                for(int i=0;i<message.length();i++)

                {

                    tv.append("Message: "+ message.getString(i) +"\n\n");
                    //attachment.put("Message: ","\n\n");

                }
                MessageToPost=tv.getText().toString();
                postToWall(MessageToPost);// called the method having logic to post on wall and sending the textview text to to post as message

                } catch (JSONException e)
                {e.printStackTrace();
                }

                catch(Exception ex)
                {ex.printStackTrace();}

                }


        };

3) method for posting the message 3)发布消息的方法

public void postToWall(String msg){


        Log.d("Tests", "Testing graph API wall post");
        try {
               String response = facebook.request("me");
               Bundle parameters = new Bundle();
               //parameters.putString("message", msg.toString());
               parameters.putString("message", msg);
               parameters.putString("description", "test test test");
               response = facebook.request("me/feed", parameters, 
                       "POST");
               Log.d("Tests", "got response: " + response);
               if (response == null || response.equals("") || 
                       response.equals("false")) {
                  Log.v("Error", "Blank response");
               }
        } catch(Exception e) {
            e.printStackTrace();
        }

        }

HOPE IT WILL HELP :) 希望它会帮助:)

This works: 这有效:

Use this: <center></center> 使用此: <center></center>

Instead of a br or a newline, etc. You can only do one in a row (ie. you can't increase the spacing). 而不是br或换行等。你只能连续做一个(即你不能增加间距)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM