Facebook share button: how to implement

我的梦境 提交于 2019-11-29 06:40:11

To share your web-page, you don't need to create a facebook application.

You can just put that Facebook-share image there, with an href = "http://www.facebook.com/sharer.php?u=<your url>"

Facebook's like button allows sharing as well. The code to generate that for your website is in the official documentation.

Edit the page you want to be shared, add these to the meta tags in the head.

<meta property="og:image" content="http://www. XXXX url of a jpg image you want to be displayed  on shared content has to be 200x200 pixels (make it in photoshop ect.) XXXX"/>
<meta property="og:title" content="xxxx A title you want to be dispayed in shared content xxxx"/>
<meta property="og:url" content="http://www. url of the page you want shared including the slash after .com xxx .com/"/>
<meta property="og:description" content="xxxx discription of the shared content xxx "/>

There is a list of the og properties other than these here- http://ogp.me/

Next insert this where you want the share button on your page,

<a title="xxx Share mypage.com xxx" href="http://www.facebook.com/sharer.php? u=http://www. xxx url of page you edited above xxx .com &t=xxx a title you want to use xxx" target="_blank"><img  src="http://www. xxx an image for the share button (make it in photoshop ect.)xxx" width="xx" height="xx" alt="Share"/></a>

Obviously take out the xxx's and leave the " " , if you change any of the above while testing you may have to go to facebook debugger and debug it as it sometimes hold on to the original content.

hope this helps

If you want to customize that share page, try this:

Javascript Popup Example:

var title = 'My Title';
var summary = 'This is my summary';
var url = 'http://www.mydomain.com/path/to/page';
var image = 'http://www.mydomain.com/images/myimage.png';

var fb = window.open('http://www.facebook.com/sharer.php?s=100&p[title]='+encodeURIComponent(title)+'&p[url]='+encodeURIComponent(url)+'&p[summary]='+encodeURIComponent(summary)+'&p[images][0]='+encodeURIComponent(image));
fb.focus();

This is what works.

in HTML:

<a href="http://www.facebook.com/sharer.php?u=<http://google.com">Facebook Link</a>

Where you replace http://google.com with your URL.

in PHP, if you want it to pull the url you are on:

<a href="http://www.facebook.com/sharer.php?u=<<?php echo "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; ?>">Facebook</a>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!