Welcome Guest, Not a member yet? Register   Sign In
Google client library integration in codeigniter 4
#1
Shocked 

Hi. I have installed google api client via composer and it runs good using composer. But whenever i tried to run it in browser i am facing error(attached). Composer after vendor/autoload.php load client library but browser integration needs something else. any help? thanks in advance

Attached Files Thumbnail(s)
   
Reply
#2

Stop the Earth, I'll get off(с)

CI4 includes the Composer autoloader by default. 
This line is not needed.
require ROOTPATH . 'vendor/autoload.php'; 


The controller have App\Controller namespace.
When you create instance of the Google_client() , it is called in the App\Controller context.
But in this context, the Google_client class does not exist.

Read the library documentation how to create class instance. 

Read the php documentation about namespace.
Reply
#3

Apologies for being dumb.

I have tried as suggested to look at the docs regarding this but if anyone can give me an actual link to a relevant document I would be greatly obliged.
Have required google apiclient and apiclient-services but cannot load the (in my case calendar service) class correctly such that I can use any of its functions.
Thanks in advance
Reply
#4

Here's a tutorial on custom libraries:
https://onlinewebtutorblog.com/codeignit...asy-steps/

And here's a tutorial on php namespacing:
https://www.w3schools.com/php/php_namespaces.asp
Reply
#5

(This post was last modified: 01-07-2022, 02:00 AM by captain-sensible. Edit Reason: forgot to add some points )

nobody is dumb on code; some are further down the line than others. I will give you a good piece of advice I was given :

"If you read something and don't understand it , keep reading until you do " .I've read things and was clueless yet it slowly sank in maybe by Osmosis and a week or so later I got it.




ok lets look at your Home Class and I will give you an extract of one of my classes.

So you used composer , thats fine . As already mention by iRedds you don't need the line about autoload , thats because composer takes care of that for you already. let me give you an extract of one of my controllers :

Code:
use CodeIgniter\Controller;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\OAuth;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;


Your Class Home extends BaseController is Ok but above that you need to lay out classes you will be using . IN my extract i'm using PHPMailer classes and use the "namespace" of the class and the class name itself. So you will need to add between
Code:
<?php namespace App\Controllers;
//and  
Class Home extends .....



So it will be something like :
Code:
<?php namespace App\Controllers;

use CodeIgniter\Controller;
use Google\AccessToken;
use Google\Authhandler;
use Google\Http;
use Google\Service;
use Google\Task;
use Google\Utils;

Google is the namespace and eg Task is a class.


Somewhere in the Controller you will instantiate , eg in my case using PHPMailer it was :

Code:
$mail = new PHPMailer();

you may need to pass something in to para theses
have a look at :
https://github.com/googleapis/google-api...s/start.md
https://github.com/googleapis/google-api-php-client
CMS CI4     I use Arch Linux by the way 

Reply




Theme © iAndrew 2016 - Forum software by © MyBB