【问题标题】:Google Contacts API with Yii2带有 Yii2 的 Google 联系人 API
【发布时间】:2015-02-14 07:29:10
【问题描述】:

我正在尝试在 Yii2 中使用 Google 联系人 API。

谷歌提供了composer接口,所以我加了

"google/apiclient": "1.0.*@beta"

到我的 composer.json 并做了“作曲家更新”

现在 - 我如何在 Yii2 控制器中实际使用它?

我有一个有效的独立测试脚本。就是这样

require_once 'GoogleClientApi/autoload.php';
$client = new Google_Client();

但是,这似乎不适用于 Yii。

我已经尝试将 require 添加到我的 index.php 文件中,如下所示(从以前的安装中复制 autoload.php,因为 autoload 似乎没有随作曲家版本提供 - 为什么会省略这个?)

require(__DIR__ . '/../vendor/google/apiclient/autoload.php');

但这会在我的控制器中调用时导致以下错误:

Call to undefined function app\controllers\Google_Client()

我已经阅读了http://www.yiiframework.com/doc-2.0/guide-tutorial-yii-integration.html 上的帖子,但这对我来说没有多大意义。

任何帮助表示赞赏。谢谢

【问题讨论】:

    标签: yii2 google-contacts-api


    【解决方案1】:

    您的代码几乎是正确的:

    require_once 'GoogleClientApi/autoload.php';
    $client = new \Google_Client();
    

    需要“\”来指示该类存在于全局命名空间中,就像您在该段代码中一样 - 在 app\controllers 命名空间下。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-24
      • 2012-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多