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 删除虚拟显示器驱动 删除所有 Xorg 配置文件 删除显示器缓存文件 重启系统 可是依旧无法退出虚拟显示器
  • ¥15 vscode程序一直报同样的错,如何解决?
  • ¥15 关于使用unity中遇到的问题
  • ¥15 开放世界如何写线性关卡的用例(类似原神)
  • ¥15 关于并联谐振电磁感应加热
  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥66 如何制作支付宝扫码跳转到发红包界面
  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题