【问题标题】:Yii2 autoload Youtube APIYii2 自动加载 Youtube API
【发布时间】:2014-11-27 11:12:13
【问题描述】:

我试图在我的控制器中包含 youtube API。我已在此路径中解压缩了 Google youtube api

     app\components\Google

现在我应该怎么做才能包含所有 Google YouTube api 文件。当我创建 Google_Client 的对象时 它说 Google_Client 类未找到。我知道 File 不包括在内,但是当我也尝试通过

将其包括在内时
    require(Yii::$app->basePath.'/components/Google/Client.php)

再次出现同样的错误,类没有发现任何关于这个的想法?

【问题讨论】:

    标签: php youtube-api yii2 youtube-data-api


    【解决方案1】:

    我找到了使用它的方法,在composer.json 中添加了存储库 URL。

    "repositories": [
            {
                "url": "https://github.com/google/google-api-php-client.git",
                "type": "git"
            }
        ],
    

    之后,只需运行composer update 的命令,作曲家就会将该存储库复制到我的供应商文件夹中。所以我现在可以使用use \Google\Client 命名空间来使用它。

    【讨论】:

      【解决方案2】:

      您可能忘记使用它的命名空间,如下所示:

      use path\Google_Client;
      

      【讨论】:

      • 我也试过了,因为 google 在每个类之前都使用了 Google_ 前缀,并且在文件名上没有 Google_ 前缀。那么我应该在所有类文件名中添加 Google_ 前缀吗?
      • 不,亲爱的,这与文件名无关。只是,使用 app\components\Google_clients 就足够了
      猜你喜欢
      • 2023-04-08
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 2013-02-27
      • 2013-08-10
      • 2019-06-02
      • 2014-01-26
      • 1970-01-01
      相关资源
      最近更新 更多