CodeIgniter Forums
Google API php client - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Google API php client (/showthread.php?tid=76303)



Google API php client - ivan1900 - 05-01-2020

hi, I am trying to use the google client api. Following the instructions of developers.google.com/sheets/api/quickstart/php, I can't get to instantiate the client object.

I put this code in my controller:
PHP Code:
<?php namespace App\Controllers;

require_once   (__DIR__ './../ThirdParty/googleApi/vendor/autoload.php');

class 
GoogleSheetData extends BaseController
{
    public function index()
    {
        putenv('GOOGLE_APPLICATION_CREDENTIALS='.(__DIR__ './../ThirdParty/xxxxxx.json'));
        $client = new Google_Client();
.
.


but I get the error:
Class 'App\Controllers\Google_Client' not found

I appreciate any help, thanks


RE: Google API php client - jreklund - 05-01-2020

You installed it the manual way correct?

Try with:
new \Google_Client();

PS. Moved your thread to General help as it's more of a PHP7 and namespacing problem than CI4.


RE: Google API php client - ivan1900 - 05-02-2020

It has worked, I have already understood, thank you.
I have another question, yesterday I tried to install with composer. Install CI 4 first and then API Google Client. But I notice that a vendor folder has been created with a copy of the CI4 structure inside.
This is normal?


RE: Google API php client - jreklund - 05-02-2020

Great that it worked out for you!

It's the correct structure for the Appstarter.

You can read more in this thread:
https://forum.codeigniter.com/thread-76237.html


RE: Google API php client - ivan1900 - 05-02-2020

I think I just understood how composer works. It is amazing, i think that is the best option for future updates.

Thank you so much!!