无法在codeigniter中加载Google API PHP客户端库


unable to load google api php client library in codeigniter

当我使用APPPATH.'libraries/Google/Client.php'时,所有包含在require_once中的文件,即子文件(Auth/AssertionCredentials.php)

A PHP Error was encountered
Severity: Warning
Message: require_once(Google/Auth/AssertionCredentials.php): failed to open stream: No such file or directory
Filename: Google/Client.php
Line Number: 18

将"Google"文件夹复制到third_party.

在应用程序/库下创建名为google.php的新文件

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

然后使用:

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

您可以更改到库路径,要求google客户端,然后切换回CI默认路径..

    // change directory to libraries path
    chdir(APPPATH.'libraries');
    // include API
    require_once('Google/Client.php');
    // do some stuff here with the Google API
    // switch back to CI default path
    chdir(FCPATH);