Use Google Drive Api in Laravel 5

丶灬走出姿态 提交于 2019-12-01 07:13:50

问题


I'm a newbie in Laravel, and surely this question has an obvious answer, but I've not been able to connect Laravel 5 with Google Api.

I have install the Api with composer like always, and it is in my vendor folder, but now I'm not sure how to use it.

I've not found an answer to this (because this must be extremely simple).

Probably I'm missing a namespace call, or something like this.

On my IndexController, I have:

    <?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";
      }
    }

}

And the error I get is:

Class 'App\Http\Controllers\Google_Client' not found

I thought that it could be a problem with autoload_classmap, but there are all GoogleApi classes defined, like:

(...)

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

(...)

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

Thanks for your patience and your help!


回答1:


I think I have it.

I only have to set:

use Google_Client; 
use Google_Service_Drive;



回答2:


check the file composer.json

and add "vendor/google/apiclient/src/Google" in classmap array if not exist.

and run composer dump-autoload

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


来源:https://stackoverflow.com/questions/29510014/use-google-drive-api-in-laravel-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!