Facebook响应API无法在CodeIgniter中运行?

时间:2017-03-01 13:55:29

标签: php facebook codeigniter facebook-graph-api facebook-php-sdk

我正在使用facebook登录在codeigniter中创建一个网络应用程序,在发送时我创建了一个API密钥,还有一个响应redirect_uri

这里的问题是在单独的文件中执行项目时,它工作正常,但是当我尝试集成到我的项目时。 Facebook要求获得进入应用程序工作正常的许可。但问题是我没有得到Facebook的任何回复来显示值并将其存储在数据库中。

我在项目中唱的代码如下所示。 Codeigniter编码格式

application
   /----config
        /----facebook.php // "contains the appId & secret Key"
   /----controller
        /----book_your_service.php //"contains the facebook_request & facebook_response"
   /----libraries
        /----Fbconnect.php //contains the URL send and Response
        /----facebook  "Library file downloaded from github"
             /----facebook.php
             /----base-facebook.php

以下代码适用于库 - > Fbconnect.php

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

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

class Fbconnect extends Facebook
{
  public $user = NULL;
  public $user_id = NULL;
  public $fb = false;
  public $fbSession = false;
  public $appkey = 0;

  public function Fbconnect(){

    $ci =& get_instance();
    $ci->config->load('facebook', TRUE);
    $config = $ci->config->item('facebook');
    parent::__construct($config);

    $this->user_id = $this->getUser();

    //print_r($this->user_id);
    $me = null;
    if($this->user_id){
      try{
        $me = $this->api('/me');
        //echo $me;
        $this->user = $me;
      }catch(FacebookApiException $e){
        error_log($e);
      }

    }
  }
} 

book_your.php中使用的以下代码用于发送和接收来自facebook的响应。

// Facebook Login API Code
  public function facebook_request()
  {
    $this->load->library('fbconnect');
    $data = array(
      'redirect_uri' => site_url('book_your_service/facebook_response'),
      'scope' => 'email'
    );
    redirect($this->fbconnect->getLoginUrl($data));
  }
  public function facebook_login()
  {
    //session_start();
    $this->load->library('fbconnect');
    if($this->fbconnect->user){
    echo"<pre>";
    print_r($this->fbconnect->user);
    echo"</pre>";
    }else{
    echo "Could not connect this time";
    }
  }

我在这个项目中使用的facebook Bundle如下所示 https://github.com/puneetkay/Facebook-PHP-CodeIgniter.git

0 个答案:

没有答案