php - Facebook上的帖子,包含双引号的消息

时间:2013-07-10 08:54:11

标签: php facebook-graph-api

我正试图在Facebook墙上发布以下代码。该消息有时包含双引号或其他在墙上转换的字符,不知道如何解决此问题。以下是我正在使用的代码

更新

$title = get_the_title($post->ID); // using wordpress posts' title

//$title = "John's message has \"\" double quotes"; I thought it might be facebook doing something with the title. but by using raw according to Tim, it worked.

                    $attachment = array(
                        'access_token' => $smm_fb_access_token,
                        'message' => $title,
                        'name' => "Site.com",
                        'link' => $handler_url,
                    );

                    $facebook->api(sprintf('/%s/feed', $fb_id), 'POST', $attachment);

Facebook上的帖子就像那样

John’s message has ““ double quotes.

请指导我该怎么做才能让它发挥作用?

1 个答案:

答案 0 :(得分:0)

您的代码中没有任何内容可以HTML转义您的$title字符串,因此它会在其他位置转义。

您提供的HTML编码也是“花哨的引号”,而不是示例$title字符串中的ASCII字符。 (即而不是")因此,如果其他东西正在逃避它,它会故意引用它。 (像wordpress可能巧妙地做)

我建议发布更多代码,以显示其Facebook SDK之旅中的数据发生了什么

<强>更新

因为这是wordpress,所以必须在没有HTML转义的情况下检索$title字符串。避免使用转义的get_the_title,而是使用

获取原始帖子标题
$title = $post->post_title;
// rest of your code.

请注意 Wordpress过滤器不会应用到此字符串,这有望成为您想要的。如果它不是您想要的,则必须按照get_the_title进行操作,然后HTML 解码字符串。 html_entity_decode对您的情况无济于事,因为PHP无法解码unicode实体。无论如何,我强烈推荐前一种方法。