【问题标题】:Adding google api client to codeigniter将google api客户端添加到codeigniter
【发布时间】:2015-05-17 08:07:31
【问题描述】:

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

我已将所有文件上传到我的第三方文件夹。 它看起来像这样

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

        }

加载谷歌库后,家庭控制器内的所有功能都不起作用。每件事都只是显示一个空白页。

在家庭控制器内部我有一个函数'test_lib'

    function test_lib(){

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

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

有人可以帮我将 google api 客户端库添加到 codeigniter。 Tnx。

【问题讨论】:

  • 您是否启用了错误日志?几件事:如果是 CI v3,库文件应该大写,在路径分隔符之前,不需要放正斜杠。
  • Tnx 。我正在使用 V 2.2 稳定版。错误日志PHP Fatal error: Class 'Google_Config' not found in /var/www/html/lankahomes/application/third_party/Google/Client.php on line 80, referer: http://lankahomes.dev/
  • 我从这个链接下载了 Google Api 客户端。github.com/google/google-api-php-client
  • 在调用库中的任何类之前,尝试从 src 文件夹中获取 autoload.php 文件。它的工作是调用其余的文件。如果您签入示例,则在实例化类对象之前仅包含该文件。
  • 我很高兴你成功了。另外,我要感谢您以如此好的方式提出要求。非常明确的问题,提供了良好的代码和图像。编码愉快。

标签: php codeigniter google-drive-api google-api-php-client


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    我想我会采用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 等

    【讨论】:

      猜你喜欢
      • 2015-03-23
      • 2012-05-21
      • 2019-05-14
      • 1970-01-01
      • 2017-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多