Facebook “Invite” 弹出窗口

<!-- invite 按钮 -->
<a href="javascript:;" id="invite">Invite your friend</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
    });
 
    $('#invite').click(function(){
        FB.getLoginStatus(checkResponse);
    });
 
    function checkResponse(response) {
        // 如果用户尚未登录
        if (!response.authResponse) {
            FB.login(handleSessionResponse);
        } else {
            inviteFriends();
        }
    }
 
    function handleSessionResponse(response) {
        // 如果用户拒绝给权限
        if (!response.authResponse) {
            return;
        } else {
            inviteFriends();
        }
    }
 
    function inviteFriends() {
        // 调整窗口大小,仅对 display:'popup' 有效
        var uiSize = FB.UIServer.Methods["fbml.dialog"].size;
        FB.UIServer.Methods["fbml.dialog"].size = {width:620, height:560};
 
        FB.ui(
            {
                method: 'apprequests',
                display: 'popup', // popup 是 打开新窗口, dialogue 是 inline 窗口
                message: "[文字说明]"
            },
            function( response ){
                FB.UIServer.Methods["fbml.dialog"].size = uiSize;
            }
        );
    }
</script>

posted on 2011-11-30 09:54  魔GUI  阅读(435)  评论(0编辑  收藏  举报

导航