# Google Api does not load into my controller

**URL:** <https://discourse.cakephp.org/t/google-api-does-not-load-into-my-controller/11048>\
**Category:** Need Help\
**Tags:** help\
**Created:** [March 13, 2023, 11:21am UTC](https://discourse.cakephp.org/t/google-api-does-not-load-into-my-controller/11048 "2023-03-13T11:21:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cins](https://avatars.discourse-cdn.com/v4/letter/c/5f9b8f/32.png) [@cins](https://discourse.cakephp.org/u/cins)\
**Post date:** [March 13, 2023, 11:21am UTC](https://discourse.cakephp.org/t/google-api-does-not-load-into-my-controller/11048/1 "2023-03-13T11:21:47Z")

</div>

Dear,

I’m trying to import data from a Google Sheet but when I try to create my google client I got this error message :

# Class “App\Controller\Google\Client” not found📋

I well installed the plugin. It works when I use it on my view (and not from my controller)

I try to add require\_once(vendor/autoload.php) but it still not working.

Any ideas ?

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [March 13, 2023, 11:32am UTC](https://discourse.cakephp.org/t/google-api-does-not-load-into-my-controller/11048/2 "2023-03-13T11:32:43Z")

</div>

1. you don’t need to manually add the `vendor/autoload.php`. This already happens in your `webroot/index.php` .
2. Make sure to either use a FQCN like `$client = new \Google\Client();` or add a `use` statement at the top of your class like

```auto
<?php
declare(strict_types=1);

namespace App\Controller;

use Cake\Controller\Controller;
use Google\Client;

class MyController extends Controller
{
    public function myGoogleAction() 
    {
        $client = new Client();
    }
}

```

---

<div class="post-metadata">

**Author:** ![cins](https://avatars.discourse-cdn.com/v4/letter/c/5f9b8f/32.png) [@cins](https://discourse.cakephp.org/u/cins)\
**Post date:** [March 13, 2023, 12:23pm UTC](https://discourse.cakephp.org/t/google-api-does-not-load-into-my-controller/11048/3 "2023-03-13T12:23:04Z")

</div>

Thanks it works for the client.

But I still have an issue for creating a google sheet with :

$service = new Google\_Service\_Sheets($client);

Same error :

Class “App\Controller\Google\_Service\_Sheets” not found

---

<div class="post-metadata">

**Author:** ![cins](https://avatars.discourse-cdn.com/v4/letter/c/5f9b8f/32.png) [@cins](https://discourse.cakephp.org/u/cins)\
**Post date:** [March 13, 2023, 12:27pm UTC](https://discourse.cakephp.org/t/google-api-does-not-load-into-my-controller/11048/4 "2023-03-13T12:27:34Z")

</div>

Oh I found it.

I just added

use Google\Service\Sheets;

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [March 13, 2023, 12:27pm UTC](https://discourse.cakephp.org/t/google-api-does-not-load-into-my-controller/11048/5 "2023-03-13T12:27:48Z")

</div>

Same problem. If you don’t start a class name with `\` then its relative to your current namespace - therefore it tries to load the class `App\Controller\Google_Service_Sheets`.

But you need

```auto
$service = new \Google_Service_Sheets($client);

```

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [March 13, 2023, 2:30pm UTC](https://discourse.cakephp.org/t/google-api-does-not-load-into-my-controller/11048/6 "2023-03-13T14:30:57Z")

</div>

This is all very standard PHP namespace stuff, nothing whatsoever to do with CakePHP, in case you’re wondering why the Cake documentation doesn’t discuss it, or want to know how to Google up additional reading materials.
