Facebook Graph API - How to post on the wall, with new lines?

I play with the Facebook Graph API and I have one problem - I cannot find a way to post ornew lines to the wall using HTML code . How can I do that? Here is my code

<?php
include_once 'lib/facebook.php';
define("FACEBOOK_APP_ID", '10126');
define("FACEBOOK_API_KEY", '064ca1988b');
define("FACEBOOK_SECRET_KEY", '9afdf92114');
define("FACEBOOK_CANVAS_URL", 'http://apps.facebook.com/my_canv_app/');
if (isset($_GET['code'])){
    header("Location: " . FACEBOOK_CANVAS_URL);
    exit;
}

$facebook = new Facebook(array('appId' => FACEBOOK_APP_ID, 'secret' => FACEBOOK_SECRET_KEY));
$user = $facebook->getUser();
$loginUrl   = $facebook->getLoginUrl(
        array(
                'scope'  => 'email,publish_stream,user_birthday,user_location,user_about_me,user_hometown'
        )
);

if (!$user) {
    echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
    exit;
}


try {
    $uid = $facebook->getUser();
    $me = $facebook->api('/me');
    $statusUpdate = $facebook->api('/me/feed', 'post', array('message'=> 'Trying to make new line here \n <br /> Neither works', 'cb' => ''));
} catch (FacebookApiException $e) {
    echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
}
?>

how could i do that?

+3
source share
7 answers

You cannot include markup or new lines in wall racks. Previously, you could provide some FBML markup to get some basic formatting, but this has become overused. If you can include html and newlines, Facebook profiles will start to look like MySpace profiles.

Facebook pretty much disorientates all the content on the wall / profile for security reasons.

+4

.

try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
$statusUpdate = $facebook->api('/me/feed', 'post', array('message'=> 'Line 1
                                                             Line 2
                                                             Line 3
                                                             Line 4',
                                                         'cb' => ''));
+6

, , escape- \n PHP.

array('message'=> 'Trying to make new line here \n <br /> Neither works', …

, PHP , \n \ n - escape- , PHP...

Doh!

+2

%0A , :)

+1

< p > </center>

ex:

line1 <centr> </center> line2 <centp> </center> line3

NOTE: there are no spaces before and after <>

0
source

For those who would like to update this.
I use the PHP SDK and \ n works as long as it is enclosed in double quotes (""). Single quotes will not work.

So, I am extracting my data from the tiny mce block, and I am doing this:

$message = preg_replace("/<br \/>/","\n",$tiny_mce_message); // the \n must be in ""!
$message = strip_tags($message);
$this->message = utf8_encode($message);
0
source

The newline character (ASCII code 10) performs the trick.

0
source

All Articles