Facebook sdk和codeigniter不在生产中工作

时间:2015-07-03 21:30:23

标签: php facebook codeigniter facebook-php-sdk

我为Facebook SDK做了一个codeigniter库,因为我需要获得一个页面的喜欢计数。

文件夹结构为:

application
 -libraries
    -api_facebook
        -Facebook (sdk)
        -My_facebook.php

我在控制器中加载如下:

$this->load->library('api_facebook/My_facebook.php');

有线的是它在本地(MAC OS)工作,但不在生产中。控制器显示白页。如果我删除库加载,控制器将再次运行。有什么想法吗?

My_facebook.php的代码:

<?php

require_once( APPPATH . 'libraries/api_facebook/Facebook/FacebookSession.php' );
use Facebook\FacebookSession;
require_once( APPPATH . 'libraries/api_facebook/Facebook/FacebookSDKException.php' );
use Facebook\FacebookSDKException;
require_once( APPPATH . 'libraries/api_facebook/Facebook/FacebookRequestException.php' );
use Facebook\FacebookRequestException;
require_once( APPPATH . 'libraries/api_facebook/Facebook/FacebookAuthorizationException.php' );
use Facebook\FacebookAuthorizationException;
require_once( APPPATH . 'libraries/api_facebook/Facebook/FacebookRedirectLoginHelper.php' );
use Facebook\FacebookRedirectLoginHelper;
require_once( APPPATH . 'libraries/api_facebook/Facebook/FacebookRequest.php' );
use Facebook\FacebookRequest;
require_once( APPPATH . 'libraries/api_facebook/Facebook/Entities/AccessToken.php' );
use Facebook\Entities\AccessToken;
require_once( APPPATH . 'libraries/api_facebook/Facebook/FacebookResponse.php' );
use Facebook\FacebookResponse;
require_once( APPPATH . 'libraries/api_facebook/Facebook/GraphObject.php' );
use Facebook\GraphObject;



class My_facebook {
  var $ci;
  var $helper;
  var $session;
  var $permissions;

  public function __construct() {

    $this->ci =& get_instance();
    $this->permissions = $this->ci->config->item('permissions', 'facebook');

    // Initialize the SDK
    $api_id = $this->ci->config->item('api_id', 'facebook');
    $api_secret = $this->ci->config->item('app_secret', 'facebook');
    FacebookSession::setDefaultApplication( $api_id, $api_secret);
    $this->session = new FacebookSession($api_id.'|'.$api_secret);

      // Validate the access_token to make sure it's still valid
      try {
        if ( ! $this->session->validate() ) {
          $this->session = null;
        }
      } catch ( Exception $e ) {
        // Catch any exceptions
        $this->session = null;
      }

  }

  /**
   * Returns the current user's info as an array.
   */
  public function get_page_likes($page) {
    if ( $this->session ) {

            // Graph API to request user data
            $request = ( new FacebookRequest( $this->session, 'GET', $page ) )->execute();

            // Get response as an array
            $user = $request->getGraphObject()->asArray();
            $likes = $user['likes'];

        return $likes;
    }
    return 0;
  }
}**

0 个答案:

没有答案