Facebook分享动态内容

xiaoxiao2021-03-01  6

// share

//初始化:

window.fbAsyncInit = function() {

FB.init({appId:'app_id',autoLogAppEvents:true,xfbml:true,version:'v2.10'});//app_id是你的app_id

};

// 引入SDK:

(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";

fjs.parentNode.insertBefore(js, fjs);

}(document, 'script', 'facebook-jssdk'));

// 定义调用方法:

function shareToFacebook(){

var uid=1;

FB.ui(

{

method: 'share',

href: 'http:www.xxxxxxx.com/?'+'uid='+uid,//uid是被分享的链接,url带上UID=1,如:http://www.xxxxxxx.com/?uid=1,uid可要可不要

},

// callback:

function(response) {

  if (response && !response.error_message) {alert("Posting completed.")}

  else {alert("Error while posting.")}

}

// 调用事件:

$(".share_facebook").click(function(){

  shareToFacebook();

})

以上方法会自动分享网站的HTML结构里的title和content,等

想要自定义title和content,又不想改变head标签里的title,用一下方法可以解决:

<!-- share -->

<meta property="og:title" content="Pinduoduo">

<meta property="og:type" content="website">

<meta property="og:image" content="www.baidu.com/img/bd_logo1.png">

<meta property="og:description" content="share get less">

<!-- share end -->

 

转载请注明原文地址: https://www.6miu.com/read-4150289.html

最新回复(0)