添加 google api 客户端到 codeigniter

Adding google api client to codeigniter

我想在 codeigniter 中使用 php 将文件上传到 google 驱动器。首先,我正在尝试将 google api 客户端集成到 codiginator。

我已将所有文件上传到我的 third_party 文件夹中。 看起来像这样

我在我的 libraries 文件夹中创建了一个名为 google.php 的文件

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

        ?>

然后我像这样将库加载到我的家庭控制器中

        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');

        }

加载 google 库 none 后,家庭控制器内的函数正在运行。每件事都只是显示一个空白页。

在家庭控制器中我有一个功能'test_lib'

    function test_lib(){

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

当我加载页面时。我得到一个黑页,没有错误或显示。

谁能帮我把 google api 客户端库添加到 codeigniter。 Tnx.

正如我已经提到的,按照存储库中的示例, Google/autoload.php 应该包括在前面 使用 classes/instantiating 个对象。在您的情况下,它是 APPPATH . 'third_party/Google/autoload.php' 文件。

我想我会采用 this response 的方法,在库中创建一个库文件,将其称为 Google.php 只是要包含的文件是 autoload.php 而不是 Client.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/autoload.php';

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

然后将其作为普通库包含在自动加载或每个您想使用该库的地方

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

然后从你加载库的地方回显

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

输出应该类似于 1.1.5 等等