Line break in Facebook status update via Graph API

2019-01-11 13:24发布

问题:

I'm writing a simple Facebook status update web app that uses Graph API. It works well except for when I'd like to include a line break in the status message. I've tried adding a simple HTML
tag, but this is just rendered as text.

Anyone know if this is possible, and if so, how?

回答1:

It sounds silly, but this works: Insert <center></center> where you would normally put <br>.



回答2:

\r\n seems to work just fine to get line breaks in facebook



回答3:

Please observe the new line that is used in the below code (an enter is hit inside the editor), that serves the purpose of adding new line to a post at a specific location:

    $fb_status_with_new_line = "Text before new line" . "
    " . "Text after new line";


回答4:

If you replace return characters (\r) with new line characters (\n) you can achieve the desired result.

Enjoy...



回答5:

%0A might work, i think i used that on one of my apps before.

HTML Decimal: &#10;
HTML Hexadecimal: &#x0A;
Java Hexadecimal: \u000A (Common To Javascript)
URL Hexadecimal: %0A
Escape Sequence: \n

HTML tag : <br>

Hope these come in handy :)



回答6:

As of Dec 2013, this works (break lines in code):

$facebook->api('/me/feed', 'post', array('message'=> 'Line 1
                                             Line 2
                                             Line 3
                                             Line 4',
                                             'cb' => ''));


回答7:

I've tried <center></center> it didn't work. I've tried <br> it didn't work. I've tried with invisible html characters, it didn't work. I've tried with '\n' it didn't work.

However when I used "\n" instead of '\n' it worked. But this was recognized directly by the php before it was uploaded to facebook. So my suggestion is using double quotes with string messages in facebook posts.



回答8:

If you're using PHP or any language just add chr(10) and this will add a break :) ASCII Solution :P



回答9:

If you are using PHP, you can do like this:

$message = str_replace('\r\n', "\n", $message); // input is from textarea
$ret_obj = $facebook->api('/me/photos', 'POST', array(
                                             'source' => '@' . $photo['file_source'],
                                             'message' => $message)
                                            );

Please use double quote "\n" instead '\n'



回答10:

\n Worked Its smallest an easiest way to add line breaks



回答11:

You need to add carriage return i.e \n\r because facebook accept only enter for new line.



回答12:

\n works. You just need to add it to the message param



回答13:

\n working I checked now on twitter. $post = $connection->post('statuses/update', array('status' => "first line \n second line")); Just do it like so, It will work for other social media also



回答14:

if You are using iOS mobile platform the \n will supports fine.. message = encodeURIComponent(message) .. bur for android nothing is working for me searching for me..



回答15:

I use the messenger API with PHP. For me, the string '\n' is working. Beware that this is not the newline character (aka "\n"). No, it's '\' followed by 'n', aka "plain antislash-N".



回答16:

None of the solutions offered worked for me when trying to post a comment on Facebook using Chrome. The only solution I have found is to highlight text that has a linefeed, then paste in that text, then erase all of the paste except the linefeed.