android - Google API Client Library giving PHP error

994

I installed the Google API Client Library on my Ubuntu Server 16.04 using Composer and I am following up their guidance on their webpage.

Whenever, I need to verify a G suite account, I am including this code:

require_oncevendor/autoload.php; But it is throwing a500 internal error.

The details of the error are

<br /><b>Fatal error</b>: require_once(): Failed opening required '../../../../vendor/autoload.php' (include_path='.:/usr/share/php') in <b>/var/www/html/php/insert.php</b> on line <b>6</b><br />

I ran thefind . -name autoload.php command, and found out that the file is located at./vendor/autoload.php and because of that I am using therequire_once('../../../../vendor/autoload.php'); as it maps to the right path. Still, I get the error above.

I tried usingrequire_once __DIR__ . '/vendor/autoload.php' as suggesed in the answer by Alex below, but I get the following error now.

<br /><b>Fatal error</b>: require_once(): Failed opening required '/var/www/html/php/vendor/autoload.php' (include_path='.:/usr/share/php') in <b>/var/www/html/php/insert.php</b> on line <b>6</b><br />

I need that file for the Library to run.

793

Answer

Solution:

Assumingcomposer.json is located in the same directory asinsert.php, therequire line should be like this:

require_once __DIR__ . '/vendor/autoload.php'

__DIR__ is translated to absolute path of the directory where current script is located, and'/vendor/autoload.php' is a relative path from the directory to theautoload.php.

People are also looking for solutions to the problem: php - Laravel - Fetch data using Auth

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.