在Laravel 5中使用Google Drive Api


Use Google Drive Api in Laravel 5

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

我像往常一样用composer安装了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’,

谢谢你的耐心和帮助!

我想我有了。

我只需要设置:

use Google_Client; 
use Google_Service_Drive;

检查文件composer.json

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

并运行composer dump-autoload

"autoload": {
        "classmap": [
            "vendor/google/apiclient/src/Google"
        ]
}