简体   繁体   English

JavaScript的Facebook共享不是真的工作

[英]javascript facebook share not really working

I'm working with facebook share. 我正在使用Facebook分享。 Here is my sample code: 这是我的示例代码:

function fbShare(url, title, descr, image, winWidth, winHeight) {
        var winTop = (screen.height / 2) - (winHeight / 2);
        var winLeft = (screen.width / 2) - (winWidth / 2);
        window.open('http://www.facebook.com/sharer.php?s=100&p[title]=' + encodeURIComponent(title) + '&p[summary]=' + encodeURIComponent(descr) + '&p[url]=' + encodeURIComponent(url) + '&p[images][0]=' + encodeURIComponent(image), 'sharer', 'top=' + winTop + ',left=' + winLeft + ',toolbar=0,status=0,width=' + winWidth + ',height=' + winHeight);return false;
    }

I have some article want to share to facebook. 我有一些文章想分享到Facebook。 there are some article successful with title, content and image. 有一些文章的标题,内容和图像都很成功。 but some article share title or content only. 但某些文章仅共享标题或内容。 I have checked my meta tag that was fine. 我检查了我的meta标签,很好。 So i don't know what happens now. 所以我不知道现在会发生什么。 Can anybody help me? 有谁能够帮助我?

Thanks a lot. 非常感谢。

I don't think you can set the desired image directly by passing the info via HTTP GET method, Facebook uses a set of Open Graph tags (see section 3) to determine the data in their Share Dialog. 我认为您不能通过通过HTTP GET方法传递信息来直接设置所需的图像,Facebook使用一组Open Graph标签 (请参阅第3节)来确定其“共享”对话框中的数据。

In order to set the desire image to be displayed, you should include the following meta tag in the header section of the HTML code of the webpage that you want to share: 为了设置要显示的期望图像,您应该在要共享的网页的HTML代码的标头部分中包含以下元标记:

<meta property="og:image" content="http://www.example.com/img-to-be-shared.jpg"/>


You may also take a look at this official documentation for sharing: Facebook Share Dialog 您也可以查看以下官方共享文档: Facebook“共享”对话框

If you want to share something through Facebook there is 2 ways to do it using the 1)share dialog[this does not allow much customization] 2)using open graph api calls[post that appear can be customized completely]. 如果您想通过Facebook分享某些内容,则可以使用1)分享对话框[这不允许过多的自定义] 2)使用开放式图形API调用[出现的帖子可以完全自定义],共有2种方法。 please refer the following post which will help you. 请参考以下文章,这对您有帮助。
FB.getLoginStatus() called before calling FB.init() and this 调用FB.init()之前先调用FB.getLoginStatus()
Facebook share custom story on my timeline using javascript sdk or the official documentation is also helpful https://developers.facebook.com/docs Facebook使用javascript sdk在我的时间轴上分享自定义故事,或者官方文档也很有帮助https://developers.facebook.com/docs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM