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 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码