如何在没有SDK或自定义应用ID的情况下创建Facebook共享按钮?

Kok*_*oko 40 facebook

我正在查看Facebook的分享按钮最新更新. 似乎不再可能在网站中包含分享按钮而不包括Facebook javascript SDK,或者在某个地方提供Facebook应用程序以提供应用程序ID?

分享按钮示例1使用Facebook SDK

FB.ui({
  method: 'share',
  href: 'https://developers.facebook.com/docs/',
}, function(response){});
Run Code Online (Sandbox Code Playgroud)

共享按钮示例2使用自定义应用程序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
Run Code Online (Sandbox Code Playgroud)

问题:如何使用一行代码为Facebook构建简单明了的共享按钮,不需要库和应用程序ID?

Rez*_*eza 67

你可以使用facebook sharer链接和一个简单的弹出窗口来完成这项工作

$("#facebookShareLink").on("click",function(){
    var fbpopup = window.open("https://www.facebook.com/sharer/sharer.php?u=http://stackoverflow.com", "pop", "width=600, height=400, scrollbars=no");
    return false;
});
Run Code Online (Sandbox Code Playgroud)

  • 谢谢.我认为这种方法已被弃用,但很显然,Facebook再次允许它:http://www.joshuawinn.com/facebooks-sharer-php-longer-deprecated-2014/ (3认同)

Car*_*ela 10

有可能的.不需要FB应用程序来简单地共享URL.创建一个简单的弹出窗口并使用Facebook共享对话框.

https://developers.facebook.com/docs/sharing/reference/share-dialog目前, 它仍然包含在他们的API中.

window.open("https://www.facebook.com/sharer/sharer.php?u=http://www.gmanetwork.com/news/", "pop", "width=600, height=400, scrollbars=no");
Run Code Online (Sandbox Code Playgroud)

  • 查看6/15/18的链接,所有示例都表明它需要appid.共享网址似乎仍然有效 (2认同)

Flo*_*rin 7

创建每次都会弹出窗口的功能.

function openURLInPopup(url, width, height, name) {
    if (typeof(width) == "undefined") {
        width = 800;
        height = 600;
    }
    if (typeof(height) == "undefined") {
        height = 600;
    }
    popup(url, name || 'window' + Math.floor(Math.random() * 10000 + 1), width, height, 'menubar=0,location=0,toolbar=0,status=0,scrollbars=1');
}
Run Code Online (Sandbox Code Playgroud)

那你的链接应该是这样的For Twitter:

 <a class="btn_twitter" onclick="openURLInPopup('http://twitter.com/home?status=http://www.domain.ro/url.html',600, 400); return false;" href="#" target="_blank">Twitter</a>
Run Code Online (Sandbox Code Playgroud)

对于Facebook:

<a class="btn_fb" onclick="openURLInPopup('http://www.facebook.com/sharer.php?u=http://www.domain.ro/url.html',600, 400); return false;" href="#" target="_blank">Facebook</a>
Run Code Online (Sandbox Code Playgroud)

对于谷歌

<a class="btn_gplus" onclick="openURLInPopup('https://plus.google.com/share?url=http://www.domain.ro/url.html',600, 400); return false;" href="#">gplus</a>
Run Code Online (Sandbox Code Playgroud)

  • @Wesley不难猜出"弹出"功能会是什么样子.事实上,他可以用这样的内容完成它`var newwindow = window.open(url,name ||'window'+ Math.floor(Math.random()*10000 + 1),'width ='+ width +',height ='+ height); if(window.focus){newwindow.focus();}` (4认同)
  • 没用,"弹出"功能不包括在内. (2认同)

Jos*_*osh 6

如果您想添加自己的(可能是动态的)文本,可以将 quote 参数添加到链接中:

https://www.facebook.com/share.php?u=example.com"e=您的+文本+此处