为什么Facebook分享按钮可以从元标记中引用参数,而不是我指定的? [英] Why is Facebook share button pulling parameters from the meta tags instead of my specified ones?

查看:120
本文介绍了为什么Facebook分享按钮可以从元标记中引用参数,而不是我指定的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经在动态创建的页面中分享按钮,该页面从页面共享特定内容:

I used to have share buttons in a dynamically created page that shared specific content from the page:

<a class="share" onclick="window.open('http://www.facebook.com/sharer.php?s=100&amp;p[title]=TITLE&amp;p[summary]=SUMMARY&amp;p[url]=http://www.facebook.com&amp;&amp;p[images][0]=imageurl', 'newwindow', 'width=555, height=315'); return false;"></a>

这导致了一个共享窗口,其内容是在上述代码中的参数中指定的(TITLE ,SUMMARY,IMAGEURL,URL等)。然而,似乎最近Facebook不赞成使用此代码,现在发生的是当您尝试分享时,您会看到我指定的参数,但是一旦您在Facebook上发布不同的内容,就会显示!

This resulted in a share window with the content that was specified in the parameters inside the above code (TITLE, SUMMARY, IMAGEURL, URL, etc). It seems, however, that recently Facebook deprecated this code and now what's happening is that when you try to share, you see my specified parameters but once you post them on Facebook different content shows up!

而不是看到我指定的参数,似乎Facebook抓取了URL中指定的页面,并查找该页面上的元标记中的信息。这意味着我的所有分享按钮现在都在发布相同的元标记。

Instead of seeing my specified parameters, it seems like Facebook crawls the page that's specified in the URL and looks for the information inside the meta tags on that page. This means that all my share buttons on the page are now posting the same meta tag.

任何人都知道如何解决这个问题或基本上共享自定义内容?

Anyone know how I can fix this or basically share custom content?

推荐答案

您可以在服务器上创建一个文件,该文件为正确的元标记提供有效的HTML文件。

You can create a file on your server that serves a valid HTML file with the correct meta tags.

shared.php?title = Hello& description = FooBar& image = URL& link = LINKURL

<html><head>
  <meta property="og:title" value="<?php echo $_GET['title'] ?>" />
  <meta property="og:description" value="<?php echo $_GET['description'] ?>" />
  <meta property="og:image" value="<?php echo $_GET['image'] ?>" ?>
  <script type='text/javascript'>
     setTimeout(function() { 
        document.location = "<?php echo $_GET['link'] ?>"; }, 500
     );
  </script>
</head></html>

现在只需将该文件传递给sharer.php,将所有参数传递到这个目录中,就像这样:

Now just pass this file with the sharer.php, passing all your parameters into this, like so:

<div 
    class="fb-share-button" 
    data-href="http://YOURSERVER.com/shared.php?title=Hello&amp;description=FooBar&amp;image=URL&amp;link=LINKURL" 
    data-type="button_count">
</div>

或使用原始的JS代码:

Or with your original JS code:

<a class='share' onclick="window.open('https://www.facebook.com/sharer/sharer.php?app_id=YOURAPPID&sdk=joey&u=http%3A%2F%2Fyourserver.com%2Fshared.php%3Ftitle%3DHello%26description%3DFooBar%26image%3DURL%26link%3DLINKURL&display=popup', 'newwindow', 'width=555, height=315'); return false;"></a>

当Facebook抓取您的网址时,由于它传递了相同的URL参数,相同的元标记将每次都要创建。

When facebook comes crawling your URL, since it passes along the same URL parameters, the same meta tags will be created every time.

需要稍微延迟Javascript URL重定向才能避免Facebook抓取器通过重定向到最终目的地;用户点击Facebook Feed中的链接仍将被重定向到最终位置。

A slight delay in the Javascript URL redirect is required to avoid Facebook crawler following through the redirect to the final destination; users clicking on the link in Facebook feed will still get redirected to the final location.

这篇关于为什么Facebook分享按钮可以从元标记中引用参数,而不是我指定的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆