0

我什么都试过了。我将我的域更改为 localhost 以外的域。

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

class MY_Controller Extends CI_Controller
{
    var $data;
    var $master;

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

        $this->data = array();
        $this->master = "layout/master";

        parse_str( $_SERVER['QUERY_STRING'], $_REQUEST );
        $CI = & get_instance();
        $CI->config->load("facebook",TRUE);
        $config = $CI->config->item('facebook');
        $this->load->library('Facebook', $config);

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

        if ($user == 0)
            $this->data['login_url'] = $this->facebook->getLoginUrl(array("scope" => "user_about_me"));
        else{
            $user = $this->facebook->api('/me');
            $this->data['logout_url'] = $this->facebook->getLogoutUrl();
        }
        print_r($user);
        print_r($this->facebook->getAccessToken());
    }
}

为什么我成功获取了AccessToken,但$user 仍然返回0?我搜索了整个stackoverflow和谷歌。

facebook 成功将我重定向回我的网站,如果我不清楚..

4

2 回答 2

1

调整你的代码

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

    $this->data = array();
    $this->master = "layout/master";

    parse_str( $_SERVER['QUERY_STRING'], $_REQUEST );
    $CI = & get_instance();
    $CI->config->load("facebook",TRUE);
    $config = $CI->config->item('facebook');
    $this->load->library('Facebook', $config);
}

function facebook_login()
{    

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

    if($user == 0){

        $loginUrl = $this->facebook->getLoginUrl(array("scope"=>"user_about_me"));
        redirect("$loginUrl","location");

    } else {

        $user_info = $this->facebook->api('/me');
        print_r($user_info);

    }
}
于 2013-06-19T17:41:55.827 回答
0

我花了好几个小时尝试了许多修复程序,并注意到我的域被设置为http://domain.co.ukfacebook 而getLoginUrl指向http://www.domain.co.uk.

于 2013-08-16T14:25:38.423 回答