I have a problem while I implement a feature which posts to Facebook. I need to add a /
character to the caption. Unfortunately, if that is inside the caption string, then on Facebook the part after the slash is not shown. If I define a caption like foo.bar/username
then foo.bar
will be shown as the caption. This is not desirable. I tried to escape it with \/
, in that case, foo.bar\/username
appeared as the caption. Is there away to show the string containing the slash as caption?
EDIT: I will give you more details about the problem, since it is seems it is not reproducible in all cases. I have this code, invoking posting to wall:
if (fRequest::get("share") === "facebook") {
$title = "Ask or tell me anything anonymously ";
$uri = QM::$mainSiteName.User::current()->getUsername();
$desc = "";
$msg = "";
$pic = QM::$mainSiteName . "images/facebook-share-my-link-200x200.png";
$caption = $uri;
$action_name = "Ask " . $_SESSION["username"] . " anything";
$action_link = $uri;
App::CurrentUser()->postToFacebookWall($title, $uri, $desc, $msg, $pic, $caption, $action_name, $action_link);
}
The code above calls the postToFacebookWall
function of the user class:
public function postToFacebookWall($title, $uri, $desc, $msg = null, $pic = null, $caption = null, $action_name = null, $action_link = null, $uid = 'me') {
try {
$data = array(
'name' => $title,
'link' => $uri,
'description' => $desc
);
if ($pic) {
$data['picture'] = $pic;
}
if ($caption) {
$data['caption'] = $caption;
}
if ($action_name) {
$data['actions'] = json_encode(array('name' => $action_name, 'link' => $action_link));
}
Facebook\FacebookAccessor\FacebookAction::facebookActionFactory("post", array("url" => $uri, "params" => $data));
} catch (Exception $e) {
return false;
}
return true;
}
The code above triggers the action factory:
public static function facebookActionFactory($actionKey, $params) {
$element = new FacebookAction($actionKey, $params);
switch ($actionKey) {
case FacebookActionPrivilege::$ACTION_POST_KEY: return $element->post($params["params"]);
case FacebookActionPrivilege::$ACTION_FIND_FRIENDS_KEY: return $element->findFriends($params["params"]);
case FacebookActionPrivilege::$ACTION_PICTURE_KEY: return $element->getPicture($params["params"]);
}
}
which, on its turn, triggers the post method:
public function post($params) {
if (($this->getIsPossible()) && (is_array($params))) {
$postRequest = new FacebookRequest(FacebookActionPrivilege::getSession(), 'POST', '/me/feed', $params);
$postResponse = $postRequest->execute();
return $postResponse;
}
}
the last two methods being part of the FacebookAction
class. The post method triggers the FacebookRequest
SDK constructor, posting the message.
Note, that QM::$mainSiteName.User::current()->getUsername() generates a string, like "http://foo.bar/loremipsum"
and in the Facebook post, the caption is: foo.bar