0

我试图在我的项目中使用 facebook 登录。为此,我在 codeigniter 中使用 PHP SDK ..

一切正常,我可以登录并将数据检索到我的页面。

但我不明白为什么注销不起作用,因为当我点击注销链接时,什么也没发生。

我在互联网上搜索了很多东西并尝试过。

我不知道现在该怎么办..希望有人可以帮助我。

这是我的代码:

模型/Facebook_model

<?php
class Facebook_model extends CI_Model {

    public function __construct()
    {
        parent::__construct();

        $config = array(
                        'appId'  => 'xxxxxxxxxxxxxx',
                        'secret' => 'xxxxxxxxxxxxxxxxxxxxxx',
                        'fileUpload' => true, // Indicates if the CURL based @ syntax for file uploads is enabled.
                        );

        $this->load->library('Facebook', $config);

        $user = $this->facebook->getUser();

        // We may or may not have this data based on whether the user is logged in.
        //
        // If we have a $user id here, it means we know the user is logged into
        // Facebook, but we don't know if the access token is valid. An access
        // token is invalid if the user logged out of Facebook.
        $profile = null;
        if($user)
        {
            try {
                // Proceed knowing you have a logged in user who's authenticated.
                $profile = $this->facebook->api('/me?fields=id,name,link,email');
            } catch (FacebookApiException $e) {
                error_log($e);
                $user = null;
            }
        }

        $fb_data = array(
                        'me' => $profile,
                        'uid' => $user,
                        'loginUrl' => $this->facebook->getLoginUrl(
                            array(
                                'scope' => 'email,user_birthday,publish_stream', // app permissions
                                //'redirect_uri' => site_url('home') // URL where you want to redirect your users after a successful login
                                'redirect_uri' => base_url()
                            )
                        ),
                        'logoutUrl' => $this->facebook->getLogoutUrl(),                     
                    );

    }
}

controller/mycontroller.php(我有其他功能的搜索功能)

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Concertos extends CI_Controller {

    function __construct()
    {
        parent::__construct();      
        $this->load->model('Facebook_model');
    }
function topsecret()
    {
        $fb_data = $this->session->userdata('fb_data');

        if((!$fb_data['uid']) or (!$fb_data['me']))
        {
            redirect('home');
        }
        else
        {
            $data = array(
                        'fb_data' => $fb_data,
                        );

            $this->load->view('home', $data);
        }
    }

public function search($location)
    {
$fb_data = $this->session->userdata('fb_data');
$data ['fb_data'] = $fb_data;

            $this->load->view('home',$data);
    }

查看/home.php

  <?php 

        if(!$fb_data['me']): ?>
        Please login with your FB account: <a href="<?php echo $fb_data['loginUrl']; ?>">login</a>
        <!-- Or you can use XFBML -->
        <div class="fb-login-button" data-show-faces="false" data-width="100" data-max-rows="1" data-scope="email,user_birthday,publish_stream"></div>
        <?php else: ?>
        <img src="https://graph.facebook.com/<?php echo $fb_data['uid']; ?>/picture" alt="" class="pic" />
        <p>Hi <?php echo $fb_data['me']['name']; ?>,<br />
         <a href="<?php echo $fb_data['logoutUrl']; ?>">logout</a></p>
        <?php endif; 
        ?>
4

2 回答 2

1

由于您正在创建会话,因此当您注销时,您需要在注销功能中将其销毁。然后你需要链接到这个函数。

function logout()
{
     $this->CI->session->sess_destroy();
     // do more thing you want to do such as redirect
}
于 2013-06-09T11:42:49.970 回答
0

我不认为有什么问题。您知道 getLogoutUrl 会从 facebook.com 注销用户吗?因此,如果只想从应用程序中注销用户,我认为它需要一些其他本机代码。

于 2013-06-09T07:43:40.610 回答