Adding google api client to codeigniter

Sathya Baman picture Sathya Baman · May 17, 2015 · Viewed 11.6k times · Source

I want to upload files to google drive using php in codeigniter. First of all i am trying to integrate google api client to codiginator.

I have uploaded all the files in to my third_party folder. it look like this

enter image description here

I i have created a file called google.php inside my libraries folder

google.php file

        <?php
        if (!defined('BASEPATH')) exit('No direct script access allowed');
        set_include_path(APPPATH . 'third_party/' . PATH_SEPARATOR . get_include_path());
        require_once APPPATH . 'third_party/Google/Client.php';

        class Google extends Google_Client {
            function __construct($params = array()) {
                parent::__construct();
            }
        } 

        ?>

Then i loaded the library in my home controller like this

        function __construct() {
            parent::__construct();

          //session, url, satabase is set in auto load in the config
            $this->load->model('Home_model', 'home');
            $this->load->library('pagination');
            $this->load->library('google');

        }

After loading the google library none of the functions inside home controllers are working. Every thing just shows a blank page.

And Inside the home controller i have a function 'test_lib'

    function test_lib(){

        echo $this->google->getLibraryVersion(); 
   }

When i load the page . i get a black page no errors or showing.

Can someone help me to add the google api client library to codeigniter. Tnx.

Answer

Tpojka picture Tpojka · May 17, 2015

As I mentioned already, following examples in repository, Google/autoload.php should be included before using classes/instantiating objects. In your case it is APPPATH . 'third_party/Google/autoload.php' file.