各大社交平台的website分享功能总结

Facebook Twitter Weibo


平台分享

Facebook Share

1
2
3
4
5
<meta property="og:url"                content="https://xxxx.com/ces/"/>
<meta property="og:title" content="Me at CES2017" />
<meta property="og:description" content="Watch me at #CES2017." />
<meta property="og:image" content="https://xxxx.com/images/share-pic.jpg" />
<meta property="fb:app_id" content="354856411540227" />
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// 分享初始化
function initFacebook() {
window.fbAsyncInit = function() {
FB.init({
appId : '354856411540227',
xfbml : true,
version : 'v2.8'
});
};
(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 facebook() {
FB.ui({
method: 'share',
href: thisUrl,
hashtag: '#CES2017',
quote: 'Watch me at #CES2017. Get $50 off'
}, function(response){});
}

Twitter Share

1
2
3
4
5
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@whataccount" />
<meta name="twitter:title" content="Me at CES2017" />
<meta name="twitter:description" content="Watch me at #CES2017." />
<meta name="twitter:image" content="https://xxxx.com/images/share-pic.jpg" />
1
2
3
4
5
// 分享链接
function twitter() {
var twitterWin = window.open();
twitterWin.location.href = "https://twitter.com/intent/tweet?text=Watch me at CES2017. " + thisUrl + "&hashtags=CES2017&in-reply-to=758537561987911681";
}

Weibo Share

1
2
3
4
5
6
7
8
9
10
11
12
// 分享链接图片至微博
function weibo() {
var wb_title = encodeURIComponent('#在CES# 我在CES现场');
var wb_url = encodeURIComponent(thisUrl), //获取当前页面地址
wb_ralateUid = encodeURIComponent('5897667853'),
wb_language = encodeURIComponent('zh_cn'),
wb_appkey = encodeURIComponent('3089711580'),
wb_pic = encodeURIComponent('https://xxxx.com/images/share-pic.jpg');
var hrefStr = "http://service.weibo.com/share/share.php?url=" + wb_url + "&appkey=" + wb_appkey + "&title=" + wb_title + "&pic=" + wb_pic + "&ralateUid=" + wb_ralateUid + "&language=" + wb_language;
var weiboWin = window.open();
weiboWin.location.href = hrefStr;
}