在Laravel 5中使用Google Drive Api [英] Use Google Drive Api in Laravel 5

查看:201
本文介绍了在Laravel 5中使用Google Drive Api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Laravel的新手,当然,这个问题的答案很明显,但是我无法将Laravel 5与Google Api连接起来.

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.

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

在我的IndexController上,我有:

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

}

我得到的错误是:

找不到"App \ Http \ Controllers \ Google_Client"类

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

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

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_Client' => $vendorDir . '/google/apiclient/src/Google/Client.php',

(...)

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

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

感谢您的耐心和帮助!

推荐答案

我认为我有.

我只需要设置:

use Google_Client; 
use Google_Service_Drive;

这篇关于在Laravel 5中使用Google Drive Api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆