在Laravel 5中使用Google Drive Api

问题描述 投票:3回答:2

我是Laravel的新手,肯定这个问题有一个明显的答案,但我无法将Laravel 5与Google Api联系起来。

我总是像编辑器一样安装Api,它在我的供应商文件夹中,但现在我不知道如何使用它。

我没有找到答案(因为这一定非常简单)。

可能我错过了一个命名空间调用,或类似的东西。

在我的IndexController上,我有:

    <?php 

namespace App\Http\Controllers;

class IndexController extends Controller {

    /**
     * Show the application welcome screen to the user.
     *
     * @return Response
     */
    public function index()
    {
      $client = new Google_Client();
      $client->setApplicationName("Client_Library_Examples");
      $client->setDeveloperKey("HERE_GOES_MY_KEY");

      $service = new Google_Service_Drive($client);
      $results = $service->volumes->listVolumes();

      foreach ($results as $item) {
        echo $item['volumeInfo']['title'], "<br /> \n";
      }
    }

}

而我得到的错误是:

找不到“App \ Http \ Controllers \ Google_Client”类

我认为这可能是autoload_classmap的问题,但是定义了所有GoogleApi类,例如:

(...)

'Google_Client'=> $ vendorDir。 '/google/apiclient/src/Google/Client.php',

(...)

'Google_Service_Drive'=> $ vendorDir。 '/google/apiclient/src/Google/Service/Drive.php',

感谢您的耐心和帮助!

php laravel-5 google-api-client vendor
2个回答
12
投票

我想我拥有它。

我只需要设置:

use Google_Client; 
use Google_Service_Drive;

0
投票

检查文件composer.json

并在classmap数组中添加“vendor / google / apiclient / src / Google”(如果不存在)。

并运行composer dump-autoload

"autoload": {
        "classmap": [
            "vendor/google/apiclient/src/Google"
        ]
}
© www.soinside.com 2019 - 2024. All rights reserved.