donglu3243 2015-08-19 04:13
浏览 30
已采纳

削弱Facebook帖子的标题

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

  • 写回答

1条回答 默认 最新

  • dtv8189 2015-08-19 19:53
    关注

    After having some trial and error sessions it, I found the solution. Instead of

    $caption = "http://foo.bar/loremipsum";
    

    I am using

    $caption = "foo.bar ⁄loremipsum";
    

    ⁄ is to encode the / and since the result did not show up well on the facebook wall, I needed some space,solved by  

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 poi合并多个word成一个新word,原word中横版没了.
  • ¥15 【火车头采集器】搜狐娱乐这种列表页网址,怎么采集?
  • ¥15 求MCSCANX 帮助
  • ¥15 机器学习训练相关模型
  • ¥15 Todesk 远程写代码 anaconda jupyter python3
  • ¥15 我的R语言提示去除连锁不平衡时clump_data报错,图片以下所示,卡了好几天了,苦恼不知道如何解决,有人帮我看看怎么解决吗?
  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?