【问题标题】:How do I stop facebook sharer.php from ignoring numbers from the target url?如何阻止 facebook sharer.php 忽略目标网址中的数字?
【发布时间】:2013-01-01 06:27:57
【问题描述】:

这是我希望用户能够分享的网址: http://dealsfortherich.com/product/6379316

所以我的应用程序 (PHP) 构造了这个 URL:

https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fdealsfortherich.com%2Fproduct%2F6379316

如果您查看该链接,您会看到产品编号已被截断。 Sharer.php 忽略斜线后的数字 (%2F) 如果我将该数字设为字母数字,则可以:

https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fdealsfortherich.com%2Fproduct%2F6379316X

https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fdealsfortherich.com%2Fproduct%2FX6379316 或者 https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fdealsfortherich.com%2Fproduct%2F637X9316

添加尾部斜杠无济于事: https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fdealsfortherich.com%2Fproduct%2F6379316%2F

显然,我可以在我的应用程序中编写一个条件来处理如下网址: http://dealsfortherich.com/product/6379316X 但就搜索引擎而言,我已经复制了内容。

我应该放弃并不使用sharer.php吗?

【问题讨论】:

  • 顺便说一句,我使用 PHP 在服务器端生成此链接,而不是使用 developers.facebook.com/docs/reference/plugins/like,因为让用户的浏览器在 javascript 中构建大约 20 个这样的按钮会导致巨大的响应问题(滞后)。
  • 尾部斜杠和页面怎么样? /index.htm
  • 谢谢,这是一个很好的尝试...但我的应用程序没有很好地响应:dealsfortherich.com/product/6379316/index.htm
  • 主题标签在我的页面上工作没问题...但 sharer.php 似乎仍在截断主题标签之前的数字! facebook.com/sharer/… 再一次,如果它是字母数字,共享者会捡起它:facebook.com/sharer/…
  • 我不熟悉与 sharer.php 一起使用的正确语法,但你能把 url 用引号 'likeThis' 括起来吗?

标签: facebook url facebook-graph-api


【解决方案1】:

想通了! 问题是facebook没有抓取页面: http://dealsfortherich.com/product/6379316

facebook object debugger 表明刮板正在看到以下规范名称: http://dealsfortherich.com/product/

即使我发布了这种情况:

remove_action('wp_head', 'rel_canonical'); 

在调用 wordpress 的 get_header() 之前(它又调用 wp_head()),它应该已经删除了错误的规范链接。

问题是过滤器 fb_meta_tags(来自插件)在我认为我设置的 OG 标签之前添加了一堆 OG 标签! 果然,设置的标签之一是:

<meta property="http://ogp.me/ns#url" content="http://dealsfortherich.com/product/" />

这就是我在调用 get_header() 之前在我的 php 中解决它的方法:

add_filter( 'fb_meta_tags', 'remove_og_tags' );
function remove_og_tags( $meta_tags )
{
  $meta_tags['http://ogp.me/ns/fb#app_id'] = null;
  $meta_tags['http://ogp.me/ns#type'] = null;
  $meta_tags['http://ogp.me/ns#title'] = null;
  $meta_tags['http://ogp.me/ns#image'] = null;
  $meta_tags['http://ogp.me/ns#description'] = null;
  $meta_tags['http://ogp.me/ns#url'] = null;
  return $meta_tags;
}

这可以防止在我添加我的之前添加错误的 OG 标签:

<link rel="canonical" href="<?php echo $page_path; ?>"/>
<meta property="fb:app_id" content="xxxxxxxxxxxxx" /> 
<meta property="og:type" content="product" /> 
<meta property="og:title" content="<?php echo $the_title; ?>" /> 
<meta property="og:image" content="<?php echo $image_url; ?>" /> 
<meta property="og:description" content="<?php echo $tweet_text.$the_title; ?>" /> 
<meta property="http://ogp.me/ns#url" content="<?php echo $page_path; ?>"  />

现在一切都运行良好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-27
    • 2012-07-25
    • 1970-01-01
    • 2020-02-26
    • 2016-06-28
    • 1970-01-01
    • 2012-09-14
    相关资源
    最近更新 更多