[英]Why doesn't this Facebook share code work?
I'm trying to make a custom Facebook share function for my website, and I'm using the Facebook sharer URL to open Facebook share in a popup window. 我正在尝试为我的网站创建自定义Facebook共享功能,并且正在使用Facebook共享程序URL在弹出窗口中打开Facebook共享。 However, for some reason it doesn't work.
但是,由于某种原因,它不起作用。
What I'm doing is simple: 我在做什么很简单:
function shareFB(){
var img=$('#fb_img').html();
var text=$('#fb_share').html();
var url=$('#fb_url').html();
var full_url='http://www.facebook.com/sharer.php?s=100&p[title]=MyTitle&p[summary]='+text+'&p[url]='+url+'&&p[images][0]='+img;
window.open(full_url, 'sharer', 'toolbar=0,status=0,width=548,height=325');
}
The weird thing is, it doesn't matter what values I give to img
, text
and url
or even if I use all of them. 奇怪的是,我给
img
, text
和url
img
什么值,甚至我都使用它们都没关系。 In the example below, I removed img
completely and set text="whatever"
and url="http://www.domain.com/stats_leagues.php"
. 在下面的示例中,我完全删除了
img
并设置了text="whatever"
和url="http://www.domain.com/stats_leagues.php"
。
https://www.facebook.com/sharer/sharer.php?s=100&%3Bp[title]=SportFant&%3Bp[summary]=whatever&%3Bp[url]=http%3A%2F%2Fwww.domain.com%2Fstats_leagues.php
Yet it doesn't work - it just opens an empty popup. 但是它不起作用-只会打开一个空的弹出窗口。 Why?
为什么? I've used the same URL format for Facebook shares a dozen times and it always worked.
我对Facebook共享使用相同的URL格式已经十几次了,并且一直有效。 Even copy/pasting the formatted URL above into my browser just opens a blank page.
即使将上面格式化的URL复制/粘贴到我的浏览器中,也只会打开一个空白页面。
I don't know from where you got all those parameters, like s=
, p[title]
, etc., probably from some old version of facebook share? 我不知道您从哪里获得了所有这些参数,例如
s=
, p[title]
等,可能来自某些旧版本的facebook share?
On Facebook share button docs, under FAQ, it says: 在Facebook 共享按钮文档的“常见问题”下,它显示:
Yes, although we recommend using the Share button to offer the simplest and most consistent experience for people using your site, you can invoke the Share Dialog using a link:
<a href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fparse.com" target="_blank">
是的,尽管我们建议您使用“共享”按钮为使用您网站的用户提供最简单,最一致的体验,但是您可以使用以下链接调用“共享对话框”:
<a href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fparse.com" target="_blank">
So just change your code to: 因此,只需将代码更改为:
function shareFB() {
var url = $('#fb_url').html(); #encode url if it is not already
var full_url = 'http://www.facebook.com/sharer.php?u='+url;
window.open(full_url, 'sharer', 'toolbar=0,status=0,width=548,height=325');
}
FAQ also states that Facebook will scrape your page for additional info, like title, image, etc. It scrapes your OG meta tags from your page. 常见问题解答还指出,Facebook将刮擦您的页面以获取其他信息,例如标题,图像等。它还会刮擦您的OG元标记。 Debug it here .
在这里调试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.