[英]How can I share my news in facebook without using an URL
I'm trying to incorporate into my project a button that allows people sharing an article on facebook. 我正试图在我的项目中加入一个按钮,允许人们在Facebook上分享文章。
I want that in facebook share window appears the title and the image of news that users click to share. 我希望在facebook分享窗口中显示用户点击分享的标题和新闻图片。
But Im not having sucess doing this, because in this project, I show the summary of each news, and each news have a link "Read full article" and a link to "Share". 但是我没有这样做,因为在这个项目中,我展示了每个新闻的摘要,每个新闻都有一个链接“阅读全文”和一个“分享”的链接。
The problem is, when I click in "Read full article", my full article opens in a fancybox without any url...so this is my difficulty, how can I share my news in facebook without a url? 问题是,当我点击“阅读全文”时,我的完整文章在一个没有任何网址的fancybox中打开...所以这是我的难度,如何在没有网址的情况下在facebook上分享我的新闻?
I'm really having difficulties to understand how each news can be share on Facebook, because of my news dont have an url. 我真的很难理解每条新闻如何在Facebook上分享,因为我的新闻没有网址。
Do you see some way in order to achieve my goal? 你有没有看到某种方式来实现我的目标?
This is my php: 这是我的PHP:
//while exist news records in database
while ($result = $readNews->fetch(PDO::FETCH_ASSOC)){
echo '<article class="news">';
echo '<img class="img" src="'.BASE.'/uploads/news/'.$result['thumb'].'"/> ';
echo '<h2>'.$result['title'].'<br /></h2>';
echo '<span>'$result['date']).'</strong></span>';
echo '<p>'.$result['content].'
<a id="'.$result['id_news'].'"
class="fancybox" href="#window_fancybox'.$result['id_news'].'">
See full article </a>
</p>';
//my share link
echo '<a title="share" class="share" href="'.BASE.'">Share</a>';
//When I click in "See full article"
// it will open a fancybox with full article
echo '<div id="window_fancybox'.$result['id_news'].'" class="modal">';
echo '<h2>'.$resultt['title'].'</h2>';
echo '<span>'.$result['date'].'</span><br />';
echo '<img class="img" src="'.BASE.'/uploads/news/'.$result['thumb'].'"/>';
echo '<p>'.$result['content'].'</p>';
echo '<span class="close_fancy">Close modal</span>';
echo '</div>';
echo '</article>';
}
This is my script to share on facebook: 这是我在Facebook上分享的脚本:
$('.share').click(function(){
urlshare = $(this).attr('href');
alert(urlshare);
window.open('http://www.facebook.com/sharer.php?u=' +urlshare,'My website',"width=500,height=400,status=yes,toolbar=no,menubar=no,location=no");
return false;
})
You can see my example here: (my fancybox share window is opening all white) 你可以在这里看到我的例子:(我的fancybox共享窗口全部打开白色)
http://ei-test.netau.net/#fancybox_window1 http://ei-test.netau.net/#fancybox_window1
Didn't test it myself, but this is how I understand it: 没有自己测试,但这是我理解它:
when hovering (and maybe also when clicking) See full article an url ending with #window_fancybox_SOMETHING_
should apear. 当悬停时(也可能在点击时) 查看完整文章 ,以
#window_fancybox_SOMETHING_
结尾的URL应该是apear。
This is the url you need to provide to facebook. 这是您需要提供给Facebook的网址。
Try this, I know this is bad patch but it works :) 试试这个,我知道这是不好的补丁,但它的工作原理:)
$(document).ready(function() {
var popupURL = location.href.split("#");
if(popupURL.length > 1) {
var action = popupURL[popupURL.length-1];
$('a.fancybox[href="#'+action+'"]').trigger("click");
}
});
Something i want to know, Do you use netau host or something like that ? 我想知道的事情,您是否使用netau主机或类似的东西? These domains and its subdomain are secured by facebook.
这些域名及其子域名由Facebook保护。 And when you use it within https://www.facebook.com/sharer/sharer.php?u= , It gives blank page.
当您在https://www.facebook.com/sharer/sharer.php?u=中使用它时,它会给出空白页面。 I write these lines to aware you if you did know.
如果你知道的话,我会写下这些线来了解你。
And, There is no a big problem in what you want, If you are using a valid url and not secured from facebook. 并且,如果您使用的是有效的网址并且没有从Facebook获得保护,那么您想要的内容就不会出现大问题。 You will not get that blank page.
你不会得到那个空白页面。 But the problematic point in your idea is that facebook get the title, description and the image"thumbnail of news" from html of your page, So when everyone click share button get the same title, description and the thumbnails.
但你的想法中有问题的一点是,facebook从你的页面的html获取标题,描述和图像“新闻缩略图”,所以当每个人点击分享按钮时,获得相同的标题,描述和缩略图。 So to handle that i suggest to make a small script behind the scene in individual page to handle that.
所以要处理我建议在单个页面中的场景后面制作一个小脚本来处理它。 If that makes sense tell me, And i will be happy to help.
如果这有意义告诉我,我会很乐意提供帮助。
go to facebook developers page and create an app and add this in the body of you page 转到Facebook开发人员页面并创建一个应用程序并将其添加到您页面的正文中
<div id="fb-root">
</div>
<script> (function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&appId=YOUR_APP_ID&version=v2.0";
fjs.parentNode.insertBefore(js, fjs);
} (document, 'script', 'facebook-jssdk'));
</script>
replace YOUR_APP_ID with the appid you get from facebook 用你从facebook获得的appid替换YOUR_APP_ID
And add this where you want the share button.. 并将其添加到您想要分享按钮的位置..
<div class="fb-like" data-layout="standard" data-action="like" data-show-faces="false"
data-share="true" width="100px">
Add a meta tag for the share image to be used by facebook 为Facebook使用的共享图像添加元标记
<meta property="og:image" content="http://www.example.com/images/logo.png" />
Your hosting doesn't seem to support sharing on Facebook. 您的托管似乎不支持在Facebook上分享。 The shortcode link to share any link on Facebook is :
在Facebook上分享任何链接的短代码链接是:
http://www.facebook.com/sharer.php?u= &t=
where, u
is the url
and t
is the title
of the page. 其中,
u
是url
, t
是网页的title
。
Now, when I try to share your article on Facebook with the following link: 现在,当我尝试使用以下链接在Facebook上分享您的文章时:
https://www.facebook.com/sharer/sharer.php?u=http://ei-test.netau.net/&t=United%20FC%20win%20the%20game
nothing really shows up. 什么都没有显示出来。 But, if you try another link, such as:
但是,如果您尝试其他链接,例如:
https://www.facebook.com/sharer/sharer.php?u=http://www.infismash.com/hover-social-buttons-wordpress/&t=United%20FC%20win%20the%20game
it clearly shows the sharing option on Facebook. 它清楚地显示了Facebook上的共享选项。
Basically, I think that your problem will be solved if you try another host. 基本上,我认为如果您尝试其他主机,您的问题将得到解决。 Also, keep in mind that many Facebook doesn't support many free hosting sites.
此外,请记住,许多Facebook不支持许多免费托管网站。
Since you want to share individual modal windows
, what you could do is try to give each modal window an identifier like #identifier-1.fancybox-overlay .fancybox-overlay-fixed
. 由于您想要共享单独的
modal windows
,您可以尝试为每个模态窗口提供一个标识符,例如#identifier-1.fancybox-overlay .fancybox-overlay-fixed
。 Have a look at identifier-1 . 看看identifier-1 。 This
1
would be the id
for each post. 这个
1
将是每个帖子的id
。 So, when anyone clicks on your link like http://ei-test.netau.net/#identifier-1
, a window would open with the modal in an active state. 因此,当任何人点击您的链接(如
http://ei-test.netau.net/#identifier-1
,将打开一个窗口,其中模式处于活动状态。
Facebook sharer.php has been deprecated, you'll need to use their 'Share Dialog', which does require setting up an APP ID on facebook for your domain. Facebook sharer.php已被弃用,您需要使用他们的“分享对话”,这需要在Facebook上为您的域设置APP ID。
https://www.facebook.com/dialog/share?
app_id=145634995501895
&display=popup
&href=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2F
&redirect_uri=https%3A%2F%2Fdevelopers.facebook.com%2Ftools%2Fexplorer
However this method does pull in meta data from the URL you've provided, you can use their javascript API to give your share's a unique title, description and url. 但是,此方法会从您提供的网址中提取元数据,您可以使用其JavaScript API为您的共享提供唯一的标题,说明和网址。
Reference: https://developers.facebook.com/docs/sharing/reference/share-dialog#redirect https://developers.facebook.com/docs/javascript/quickstart/v2.1 参考: https : //developers.facebook.com/docs/sharing/reference/share-dialog#redirect https://developers.facebook.com/docs/javascript/quickstart/v2.1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.