php – 在Laravel 5中使用Google Drive Api

我是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";
      }
    }

}

而我得到的错误是:

Class ‘App\Http\Controllers\Google_Client’ not found

我认为这可能是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;
上一篇:imx8项目常用操作


下一篇:git add 不能提交 vendor下面的一个文件夹