php 脸书分享者
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4118572/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Facebook Sharer
提问by Wright-Geek
I am trying to set up facebook sharer.php
Can someone give me some direction on this. How do I get an image and text to appear?
I am trying to achieve a similar effect to the share link on espn.com.
我正在尝试建立 facebooksharer.php
有人可以给我一些指导吗?如何让图片和文字出现?我正在尝试实现与 espn.com 上的共享链接类似的效果。
Many Thanks
非常感谢
回答by ceejayoz
Did you try the documentation?
您是否尝试过文档?
http://developers.facebook.com/docs/share
http://developers.facebook.com/docs/share
Placing meta tags in your page's head makes the right thumbnail and description show up in that dialog. As a bonus, if someone just pastes a link to your page in their Facebook status, it'll work there too.
将元标记放置在页面的头部会使正确的缩略图和描述显示在该对话框中。作为奖励,如果有人只是在他们的 Facebook 状态中粘贴指向您页面的链接,它也可以在那里工作。
<meta property="og:title" content="title" />
<meta property="og:description" content="description" />
<meta property="og:image" content="thumbnail_image" />
回答by dropson
Not sure if it is this kind of sharing you want to achieve. I'll toss it out for you anyways.
不知道是不是你想要实现的这种分享。反正我给你扔掉。
Text link:
文字链接:
<script>function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}</script><a rel="nofollow" href="http://www.facebook.com/share.php?u=<;url>" onclick="return fbs_click()" target="_blank">Share on Facebook</a>
Small icon and text:
小图标和文字:
<script>function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}</script><style> html .fb_share_link { padding:2px 0 0 20px; height:16px; background:url(http://static.ak.facebook.com/images/share/facebook_share_icon.gif?6:26981) no-repeat top left; }</style><a rel="nofollow" href="http://www.facebook.com/share.php?u=<;url>" onclick="return fbs_click()" target="_blank" class="fb_share_link">Share on Facebook</a>
Icon only:
仅图标:
<script>function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}</script><style> html .fb_share_button { display: -moz-inline-block; display:inline-block; padding:1px 20px 0 5px; height:15px; border:1px solid #d8dfea; background:url(http://static.ak.facebook.com/images/share/facebook_share_icon.gif?6:26981) no-repeat top right; } html .fb_share_button:hover { color:#fff; border-color:#295582; background:#3b5998 url(http://static.ak.facebook.com/images/share/facebook_share_icon.gif?6:26981) no-repeat top right; text-decoration:none; } </style> <a rel="nofollow" href="http://www.facebook.com/share.php?u=<;url>" class="fb_share_button" onclick="return fbs_click()" target="_blank" style="text-decoration:none;">Share</a>
回答by Pete855217
Just a note on FB images you want to appear in the 'like'. They must NOT have spaces in the image name, otherwise the image will not come across to FB. Took me a while to work out why I couldn't get images across using the FB link debugger (https://developers.facebook.com/tools/debug), and the error messages were of no help at all. But removing the spaces from the image name solved the problem.
只需注意您希望出现在“喜欢”中的 FB 图像。图像名称中不能有空格,否则图像将不会出现在 FB 中。我花了一段时间才弄清楚为什么我无法使用 FB 链接调试器 ( https://developers.facebook.com/tools/debug)获取图像,并且错误消息根本没有帮助。但是从图像名称中删除空格解决了这个问题。
If you can't get your images to display in FB, despite using the og:image tags correctly etc. check the image name to ensure it has no spaces (other non [A-Za-z0-9_-] may not work too).
如果你不能让你的图像在 FB 中显示,尽管正确使用了 og:image 标签等检查图像名称以确保它没有空格(其他非 [A-Za-z0-9_-] 可能也不起作用)。