<!-- share 按钮 -->
<
a
href
=
"javascript:;"
id
=
"share"
>Share on facebook</
a
>
<!-- facebook 相关 -->
<
div
id
=
"fb-root"
></
div
>
<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js">
</script>
<script type="text/javascript">
FB.init({
appId: appid,
// 注意替换正确的facebook app id
status:
true
,
cookie:
true
,
xfbml:
true
,
oauth:
true
});
$(
'#share'
).click(
function
(){
FB.getLoginStatus(checkResponse);
});
function
checkResponse(response) {
// 如果用户尚未登录
if
(!response.authResponse) {
FB.login(handleSessionResponse);
}
else
{
postToMyWall();
}
}
function
handleSessionResponse(response) {
// 如果用户拒绝给权限
if
(!response.authResponse) {
return
;
}
else
{
postToMyWall();
}
}
function
postToMyWall() {
FB.ui(
{
method:
'feed'
,
display:
'popup'
,
// popup 是 打开新窗口, dialogue 是 inline 窗口
description:
"Facebook"
,// 要添加的说明代码
name: 'name
',
picture: '
http:
//…/a.jpg',// 此处是要添加的图片
link: 'http:
//www.facebook.com/' //此处是要添加图片的链接地址
}
);
}
</script>