在codeIgniter中使用共享SSL的Facebook APP

时间:2013-04-07 18:21:50

标签: .htaccess codeigniter hosting ssl-certificate facebook-apps

我在hostgator.com上有一个共享ssl的主机,我在public_html(root)目录中上传了codeIgniter站点。我想开发一个网站以及Facebook应用程序。

运行Facebook应用程序时,网站运行成功并使用“登录Facebook”,这会产生网址重定向错误。

这是http url

 url(Website): http://example.org/ 

和安全网址

 https://in9.hostgator.in/~username/

在Facebook应用配置中,

  canvas url :  http://example.org/
  Secure Canvas URL : https://in9.hostgator.in/~username/ (Work in url)

当我运行facebook应用程序时,facebook会出错:

    API Error Code: 191
    API Error Description: The specified URL is not owned by the application
    Error Message: Invalid redirect_uri: Given URL is not permitted by the application configuration.

在应用程序中,没有.htaccess文件用于重定向或删除根目录中的index.php。

我已经运行了这个基本控制器代码:

    public function __construct()
{
    parent::__construct();
    $this->load->library("session");
    $this->load->helper('cookie');

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

}

/**
 * Index function
 * @access public
 * 
public function index()
{
    $userId = $this->facebook->getUser();
    // If user is not yet authenticated, the id will be zero

    if($userId == 0){
                    // Generate a login url
        $params = array(
                  'scope' => 'email,user_about_me, user_birthday, user_location');
        $url = $this->facebook->getLoginUrl($params);
        echo "<script type='text/javascript'>" . "top.location.href = '" . $url. "';</script>";
        }
    } 

当我打印'$ url'时,查询字符串中的redirect_url为'http://in9.hostgator.in/~username/',而不是重定向到https路径。

我很困惑,代码中的错误是什么?或服务器中的一些错误配置或什么?

1 个答案:

答案 0 :(得分:2)

Facebook应用程序也有“App Domains”设置,如果画布网址不在列出的域下,则facebook sdk将无效。尝试在那里添加example.orghostgator.in

或者你可以使用facebook canvas url作为重定向uri,所以如果你的facebook应用程序的命名空间是my-facebook-app,那么你可以像这样生成登录URL:

$this->facebook->getLoginUrl(array(
    'scope' => 'email,user_about_me, user_birthday, user_location',
    // change the last segment to you app's namespace
    'redirect_uri' => 'https://apps.facebook.com/my-facebook-app/'
));

使用canvas应用程序这可能更可行,因为如果重定向uri直接指向您的安全画布URL,则用户在验证时将“松散”facebook。