dongse7261 2017-03-01 13:55
浏览 43

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

I am creating a web app in codeigniter with facebook login, and while sending I have created a API Key and also a response redirect_uri.

The problem here is while executing the project in the separate file, it's working fine, but when I was trying to integrate to my project. Facebook is asking for permission to enter to the app that's working fine. But the problem is I'm not getting any response from Facebook to display values and store it in the database.

The code which I was sing in my project is shown below. Codeigniter coding format

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

Following code is for libraries --> 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);
      }

    }
  }
} 

the following code used in book_your.php for sending and receiving the response from 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";
    }
  }

The facebook Bundle which I was using in this project is shown below https://github.com/puneetkay/Facebook-PHP-CodeIgniter.git

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 用三极管设计—个共射极放大电路
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 牛顿斯科特系数表表示