Loading google api client library in codeiniter

2019-05-23 03:41发布

问题:

first I copied the Google folder to application/third_party in codeigniter framework.

then google.php inside the application/libraries

<?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();
    }
}

and then i have created a controller named googleClass.php

<?php
class GoogleClass extends CI_Controller {
    function __construct($params = array()) {
    parent::__construct();
}
public function index(){

    $this->load->library('google');
    echo $this->google->getLibraryVersion();
   }
}

But I get the following error...

Fatal error: require_once(): Failed opening required '' (include_path='application/third_party/;.;C:\xampp\php\pear') in C:\xampp\htdocs\csvinsert\application\third_party\Google\Client.php on line 18

what I'm doing wrong ??

回答1:

I am assuming that you have autoload.php in application/third_party directory, and rest of the source in application/third_party/Google directory.

in the application/libraries/google.php remove this line.

set_include_path(APPPATH . 'third_party/' . PATH_SEPARATOR . get_include_path());

now the code google.php will be

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

require_once APPPATH . 'third_party/Google/Client.php';

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

This will get rid of that error.



回答2:

Please try this way load your libraries :include_once APPPATH . "libraries/third_party/Google/Client.php";