Where do I put the require code for autoloader.php?

525 Views Asked by At

I am clearly new at this. But I'm having trouble installing the google-api-php-client library. On Google's documentation page, it says:

After obtaining the files, include the autloader. If you used Composer, your require statement will look like this:

require_once '/path/to/your-project/vendor/autoload.php';

If you downloaded the package separately, your require statement will look like this:

require_once '/path/to/google-api-php-client/vendor/autoload.php';

I know this is probably an simple answer, but where in my project am I supposed to put the code?

Is there a file within the google-api-php-client directory that I am supposed to put this line in? Or do I need to place this line directly into my website's html in order for the library to properly install?

I am using Drupal 7 and I installed the library with composer.

1

There are 1 best solutions below

0
On

Suppose I have 3 files, mail.php, calendar.php and drive.php. With mail.php, I run a script that sends emails from my google account, with calendar.php I run a script that inserts a new event in my calendar and with drive.php I run a script that uploads a file to my drive. Each one of those files will need the require_once '/path/to/your-project/vendor/autoload.php'; after <?php. For example:

<?php session_start();

require_once '/path/to/your-project/vendor/autoload.php';

//run the rest of your script that requires interacting with google services.

Please take a look at the example in the documentation located here and the example here