如何注销Facebook API

时间:2016-02-09 08:44:38

标签: facebook codeigniter facebook-graph-api

我在Codeigniter中对logout fb帐户的编码有问题。我的控制器中有这样的代码

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

    class Welcome extends CI_Controller {

        /**
         * Index Page for this controller.
         *
         * Maps to the following URL
         *      http://example.com/index.php/welcome
         *  - or -
         *      http://example.com/index.php/welcome/index
         *  - or -
         * Since this controller is set as the default controller in
         * config/routes.php, it's displayed at http://example.com/
         *
         * So any other public methods not prefixed with an underscore will
         * map to /index.php/welcome/<method_name>
         * @see http://codeigniter.com/user_guide/general/urls.html
         */
        public function index()
        {
            return redirect('/welcome/login');
        }
        public function login(){

            $this->load->library('facebook'); // mengambil appid dan secret dari config
            // atau
            // bisa juga menggunakan
            //$this->load->library('facebook', array(
            //    'appId' => 'APP_ID',
            //    'secret' => 'SECRET',
            //    ));

            $user = $this->facebook->getUser();
            $data['judul']='Airlines Complain';
            if ($user) {
                try {
                    $data['user_profile'] = $this->facebook->api('/me');
                } catch (FacebookApiException $e) {
                    $user = null;
                }
            }else {
                // Solves first time login issue. (Issue: #10)
                //$this->facebook->destroySession();
            }

            if ($user) {

                $data['logout_url'] = site_url('welcome/logout'); // Logs off application
                // OR
                // Logs off FB!
                // $data['logout_url'] = $this->facebook->getLogoutUrl();

            } else {
                $data['login_url'] = $this->facebook->getLoginUrl(array(
                    'redirect_uri' => site_url('welcome/login'),
                    'scope' => array("email") // permissions here
                ));
            }
            $this->load->view('login',$data);

        }

        public function logout(){
            // Logs off session from website
            $this->load->library('facebook');
            $data['login_url']=null;
            $this->facebook->destroySession();
            $_SESSION['do_not_auto_login']=true;
            // Make sure you destory website session as well.

            redirect('/');
        }

    }

但注销网址适用于从我的应用程序注销,但它不适用于注销facebook帐户?如何从fb帐户注销?感谢

0 个答案:

没有答案