Open Graph User变量在授权后变为null

时间:2014-10-01 20:36:42

标签: php facebook facebook-opengraph

我正在使用Facebook的Open Graph API从他/她的帐户导入用户的图片。

但是当我点击登录按钮并打开URL时,授权后再次要求我登录。

这是我的index.php

<?php

    ini_set("display_errors",0);
    if ( !defined('ABSPATH') )
        require_once '../../../../wp-load.php';
    include_once __DIR__."/fbmain.php";
    include_once __DIR__."/facebook.php";

    if(!session_id())session_start();
    global $fbSiteUrl;
    /*$base_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']!='off') ? 'https://' : 'http://';
    $base_url .= $_SERVER['HTTP_HOST'];*/
    $fbSiteUrl = COO_PLUGIN_URL."/create-own-object/plugin-facebook";//$base_url.substr(__DIR__,strpos(__DIR__,'/phase2-newer'));

/*if(isset($_GET['logout']) && $_GET['logout']=='yes'){
    $user = null;
    $facebook->logoutFromSite();
}*/

if (!$user){
?>
    <div class="facebook_login_box" id='fbLoginBtn'>
        <div class="text-center">
            <a href="#"><img src="<?php echo $fbSiteUrl; ?>/Images/facebook_logo.png" alt="" ></a>
        </div>
        <div class="fb_login">
            <button type="button" class="fb_login_btn" style="margin-right: 90px;" onclick="authoriseToSocialMedia('<?php echo $loginUrl; ?>');">Login</button>
        </div>
    </div>
<?php
}// else { ?>
    <!--    <div class="right_side">
        <a href="<? //= $logoutUrl; ?>" onClick='loader()'><img src="Images/logout.png"></a>
    </div> -->
<?php //} ?>
<img src="<?php echo $fbSiteUrl; ?>/Images/folder_fb.png" style="display:none;">
<!-- all time check if user session is valid or not -->
<?php
if ($user) {
?>
    <div id ='FBcontent'>
        <form id ='FBcontentFrm' method="post" action="index.php">          
            <div class="folderset" id="folderList">
                <!-- Data retrived from user profile are shown here -->
                <?php
                    $albums = $facebook->api("/me/albums");
                    foreach($albums['data'] as $album){
                    ?>
                        <div class="box">
                            <a href="javascript:void(0);" onclick="showAlbum('<?php echo $album['id']; ?>')">
                                <img src="<?php echo $fbSiteUrl; ?>/Images/folder_fb.png">
                                <div style="clear: both;"></div><?php echo $album['name']; ?>
                            </a>
                    </div>
                    <?php
                    }
                ?>
                <div class="clearfix"></div>
            </div>

            <div id="fbhtmlImage">
                <!-- Album images are being loaded here. -->
            </div>
        </form>

        <script>
            if((this.window.focus() || !(this.window.closed)) && window.opener != null)
            {
                window.opener.document.getElementById('facebook_content').innerHTML = document.getElementById('FBcontent').innerHTML;
                window.opener.document.getElementById("fbLoginBtn").style.visibility="hidden";
                this.window.close();
            }
        </script>
    </div>  
<?php } ?>
<script type="text/javascript">
    function backToAlbums(){
        $('#fbhtmlImage').hide();
        $('#fbmodal-footer').hide();
        $('#folderList').show();
    }
    function showAlbum(albumId){
        $('#loader_img').show();

        <?php global $fbSiteUrl;?>
        $('#folderList').hide();
        var fbhtml = '';
        fbhtml += '<div class="image_list addimage_box_col">\
            <div class="row">\
                <div class="col-lg-2 col-sm-3 col-xs-6">\
                    <a class="pink_btn" href="javascript: void(0);" onClick="backToAlbums();">Back</a>\
                </div>\
            </div>\
            <div class="clearfix"></div>\
        </div>';

        $.ajax({
            type: "GET",
            url: "<?php echo $fbSiteUrl; ?>/fbphotos.php",
            data: { albumId: albumId }
        }).done(function(response) {
            var response = jQuery.parseJSON(response );
            var showBtn = false;
            fbhtml += "<div class='image_list addimage_box_col'>\
                <div class='row'>";
                    if(response['data'].length>0)
                    {
                        for(var x=0; x<response['data'].length; x++){
                            fbhtml += '<div class="col-lg-2 col-sm-3 col-xs-6" style="padding-top: 15px;"><div class="checkbox_left">';
                                fbhtml += '<input type="checkbox" class="css-checkbox" id="facebook_'+x+'" name="facebook[]" value="'+response['data'][x]['source']+'" />';
                                fbhtml += '<label class="css-label radGroup1" for="facebook_'+x+'"></label>';
                            fbhtml += '</div>';
                            fbhtml += '<div class="image_thumb">';
                                fbhtml += '<img class="bdr img-responsive center-block" src="'+response['data'][x]['source']+'" />';// style="width:100px !important; height:100px !important;" />';
                            fbhtml += '</div></div>';
                            showBtn = true;
                        }
                    }
                    else
                    {
                        fbhtml += '<div class="image_thumb">';
                        fbhtml += 'There are no image(s) in this album.';
                        fbhtml += '</div>';
                    }

                    fbhtml += "<input type='hidden' name='fb_copy' value='Copy Selected Files'>\
                </div>\
                <div class='row'>";
                    fbhtml += '<div class="col-lg-2 col-sm-3 col-xs-6" style="padding-bottom: 10px; padding-top: 10px;">';
                        if(showBtn == true)
                        {
                            fbhtml += "<input type='button' class='pink_btn' name='fb_copy' value='Copy Selected Files' onclick='moveImages($(\"#FBcontentFrm\").serialize())' />";
                        }
                    fbhtml += "</div>\
                </div>\
            </div>";
            $('#fbhtmlImage').html(fbhtml);
            $('#fbhtmlImage').show();
            $('#loader_img').hide();
        });
    }
</script>

<script>
/*
    function moveImages(){
        $.post(SiteURL+"wp-content/themes/mydomain/moveSelectedImages.php", $("#FBcontent").serialize(),function(data){
            alert(data);

            } );
    }*/
</script>

0 个答案:

没有答案