• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bebo and Codeignitor Error

#1
[eluser]damon311[/eluser]
All,

I am new to CodeIgniter (I'm making the switch from Rails and Java) so this may be user error. I'm getting a "api key is invalid" error when running the code below. I've copied the Bebo PHP library (http://developer.bebo.com/downloads/exam...bs-php.php [renamed to Bebo.php]) to $home/system/application/libraries/Bebo.php. The library is being loaded properly but it complains about the API key (I copied and pasted both the api and secret key from Bebo). Any ideas? Thanks

Code:
class Test extends Controller {
        
        function Test() {
            parent::Controller();
            
            require_once APPPATH . 'libraries/Bebo.php';    
            
            #load config
            $this->my_config = $this->config->item('bebo');
            
            #initialise bebo
            $apikey = $this->my_config['api_key'];
            $apisecret = $this->my_config['api_secret'];
            $this->bebo = new Bebo($apikey,$apisecret,true);
        }
        
        function index() {
            $friends = $this->bebo->friends_get();
            
            foreach($friends as $item):
                echo $item;
                echo '<hr/>';    
            endforeach;
        }
        
    }

#2
[eluser]Seppo[/eluser]
are you really using an object to store the config?
try echoing $apikey and $apisecret to check out if the valures are correctly passed.

#3
[eluser]damon311[/eluser]
Thanks for your reply. I ran the code below and the apikey and apisecret are correctly displayed, but I'm still getting "api key is invalid" message.


Code:
class Test extends Controller {
        
        function Test() {
            parent::Controller();
            
            require_once APPPATH . 'libraries/Bebo.php';    
            
            #load config
            $this->my_config = $this->config->item('bebo');
            
            #initialise bebo
            $apikey = $this->my_config['api_key'];
            $apisecret = $this->my_config['api_secret'];
            $this->bebo = new Bebo($apikey,$apisecret,true);
            echo $apikey . '<br/>';
            echo $apisecret . '<br/>';
        }
        
        function index() {
            $friends = $this->bebo->friends_get();
            
            foreach($friends as $item):
                echo $item;
                echo '<hr/>';    
            endforeach;
        }
        
    }

#4
[eluser]Seppo[/eluser]
Well... on this point I think you are having a problem with Bebo, and it has nothing to do with CI...
Try aislating this issue: create a new empty file, load the library and try using it there...
Alos make sure you have no white-space on your api key/api secret. I can't realize why else you can have this issue...

#5
[eluser]damon311[/eluser]
I tried that last night and you are correct. To get things working, I realized that I needed to add
Code:
ini_set('arg_separator.output', '&');
My apologies.

Now this is a CodeIgniter question. I read the documentation on how to automatically pass parameters to the constructors of classes placed in the libraries directory. Again, I'm new and probably did something wrong. Essentially, do I have to initialize my Bebo class in every controller? This is what I'm doing now.

Code:
function Test() {
            parent::Controller();

            ini_set('arg_separator.output', '&');
            require_once APPPATH . 'libraries/Bebo.php';

            #load config
            $this->my_config = $this->config->item('bebo');

            #initialise bebo
            $apikey = $this->my_config['api_key'];
            $apisecret = $this->my_config['api_secret'];
            $this->bebo = new Bebo($apikey,$apisecret,true);
        }

#6
[eluser]Michael Wales[/eluser]
Quote:Essentially, do I have to initialize my Bebo class in every controller?
Yes - within every controller you intend to use the Bebo API. If you are going to be using it a lot (as in everywhere) you could just make the class initialize itself. Look at any of the CI libraries for an example of how to do so.

#7
[eluser]Seppo[/eluser]
To keep it simple I would rename bebo class (for example I call it bebo_app) and I create an own bebo class that extends the real bebo class (bebo_app) and I make it do the repetitive work... something like this
Code:
class Bebo extends Bebo_app
{
    public function __construct()
    {
                ini_set('arg_separator.output', '&');    
        $CI =& get_instance();
        $CI->load->config('bebo');
        $app_info = $CI->config->item('bebo');
        parent::__construct($this->my_config['api_key'], $this->my_config['api_secret'], true);
    }
}

class Bebo_app {
  public $api_key = "";
// and so on...


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.