简体   繁体   English

Facebook API有效,但不能与Codeigniter一起使用?

[英]Facebook API works, but not with codeigniter?

I'm working on a site which uses the Facebook API to log users in, but I'm having some baffling trouble with the Facebook API itself. 我正在使用Facebook API登录用户的网站上工作,但是我在使用Facebook API本身时遇到一些莫名其妙的麻烦。 I think it's a result of using CodeIgniter. 我认为这是使用CodeIgniter的结果。

I added a PHP script that does not use Codeigniter, and it can connect. 我添加了一个不使用Codeigniter的PHP脚本,它可以连接。 It looks like this: 看起来像这样:

require_once("application/libraries/Facebook/facebook.php");

$facebook = new Facebook(array(
        'appId'  => 'appid-removed-for-question',
        'secret' => 'secret-removed-for-question',
));

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

This returns the appropriate UID from Facebook. 这将从Facebook返回适当的UID。

As soon as I try to do this using a CodeIgniter library, the UID consistently comes back as 0. Here's the library code: 当我尝试使用CodeIgniter库执行此操作时,UID始终返回0。这是库代码:

include(APPPATH.'libraries/Facebook/facebook.php');

class Fb_connect extends Facebook{

    public $user;

    public function __construct()
    {
        $CI =& get_instance();
        $CI->config->load("facebook",TRUE);
        $config = $CI->config->item('facebook');
        parent::__construct($config);

        $this->user = $this->getUser();
        echo $this->user;
    }
}

I've double and triple-checked my appid and secret in the config file, and even echoed it here to make sure it's coming through as an array correctly, but still nothing. 我已经在配置文件中对我的appid和secret进行了两次和三次检查,甚至在这里回显了它,以确保它正确地作为数组通过,但仍然没有。 $this->user; constantly returns 0 for the UID. UID持续返回0。 What am I missing? 我想念什么?

I just saw this question which talks about the uri_protocol being the problem, but I had to set $config['uri_protocol'] = 'QUERY_STRING'; 我刚刚看到这个问题 ,其中提到uri_protocol是问题,但是我必须设置$config['uri_protocol'] = 'QUERY_STRING'; to get my mod_rewrite script working in the first place, which makes me wonder if it's the same issue or not. 首先让我的mod_rewrite脚本运行,这使我想知道这是否是相同的问题。 Any advice? 有什么建议吗?

The answer to the question I linked to actually fixed the problem for me: 我链接到的问题的答案实际上为我解决了这个问题:

$config['uri_protocol'] = 
    (isset($_SERVER['HTTP_REFERER']) && 
     strpos($_SERVER['HTTP_REFERER'], 'apps.facebook.com') !== false) ? 
         "PATH_INFO" : "REQUEST_URI";

use this.. require_once($_SERVER['DOCUMENT_ROOT']."/".$this->config->item('app_folder_path')."application/libraries/Facebook/facebook.php"); 使用它。.require_once($ _ SERVER ['DOCUMENT_ROOT']。“ /”。$ this-> config-> item('app_folder_path')。“ application / libraries / Facebook / facebook.php”);

Make sure you've set the app_folder_path config variable in your config.php file. 确保已在config.php文件中设置了app_folder_path配置变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM