繁体   English   中英

facebook sdk android墙贴线休息

[英]facebook sdk android wall post line break

我正在制作一个应用程序,使用facebook sdk for android将一些信息发布到你的Facebook墙上。 这样可行,但我似乎无法在帖子上获得新的内容。 我曾尝试\\n但doesent工作。 有什么建议么?

这是我的代码:

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

谢谢,

詹姆斯福特

嗨詹姆斯我以前尝试过,即使使用HTML代码,但我认为这是不可能的。 原因是,Facebook必须有一个控制权来避免他的帖子上出现空格或换行。

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

这对我有用:

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

利用JSON在facebook上发帖..怎么样? 看这里

脚步 :-

第1步: - 在此链接中,您将了解如何使用JSON将文本设置为TEXTVIEW。

第2步: - 可能这不是你在寻找:)使用GetText().ToString将textview的文本分配给某些字符串GetText().ToString

第3步: - 使用此字符串发布到Facebook。

第4步: - 我在google搜索后花了很多时间做了同样的事情,最后通过使用这个技巧获得了结果。 ü可以看到我的帖子,我测试期间张贴在这里

第5步: - 将此文本框的可见性设置为不再使用

tv.setVisibility(View.GONE)

你完成了你的发布到Facebook ..让facebook和textview处理他们如何管理空格和新线字符:D

一些编码为像我这样的新手工作......

我点击按钮发布它

1)

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

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)发布消息的方法

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

        }

希望它会帮助:)

这有效:

使用此: <center></center>

而不是br或换行等。你只能连续做一个(即你不能增加间距)。

暂无
暂无

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

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