1

Do you guys know the reason why google api is not working when I put my website on a web server (go daddy) and how to fix it? but it is working good in localhost?

include 'system/includes/connection.php';
require __DIR__ . '/googleApi/vendor/autoload.php';
$client = new \Google_Client();
$client->setApplicationName('Google Sheets and PHP');
$client->setScopes([\Google_Service_Sheets::SPREADSHEETS]);
$client->setAccessType('offline');
$client->setAuthConfig('client_credentials.json');

$service = new Google_Service_Sheets($client);

This is the error its showing in my error log. [08-Aug-2020 01:38:38 Asia/Manila] PHP Parse error: syntax error, unexpected ':', expecting '{' in/home/y2efod66lc11/public_html/googleApi/vendor/guzzlehttp/guzzle/src/functions.php on line 14

this is what inside function.php https://hasteb.in/egehofos.xml

MJERM
  • 33
  • 6
  • here is it.. I don't know why its throwing an error.. because this is directly from google api.. and this is working in my localhost PHP Parse error: syntax error, unexpected ':', expecting '{' in/home/y2efod66lc11/public_html/googleApi/vendor/guzzlehttp/guzzle/src/functions.php on line 14 – MJERM Aug 08 '20 at 08:48
  • Your code uses syntax for PHP 7+ Most probably at host you have 5.x still. Use `phpinfo()` to verify that and/or check settings in the admin panel of your host. – biesior Aug 08 '20 at 08:51

2 Answers2

2

You have to upgrade your PHP version to 7.0 or higher, that's when return types was added.

However note that you should be on PHP 7.3 or higher as 7.1 and lower is no longer supported, and 7.2 is reaching end of life at the end of November this year. https://www.php.net/supported-versions.php

Thor Erik
  • 145
  • 7
  • I though there is something wrong with my code. so meaning I just need to direclty upgrade mh PHP version in cpanel. I will try that.. THank you @Thor Erik – MJERM Aug 08 '20 at 08:56
  • Although the googleapi with dependencies for PHP 7.3 and higher makes the googleapi not to work for me. My server runs PHP 8 and only googleapi with dependencies for max PHP 7.2 works. – Peter Westerlund Jan 10 '23 at 20:12
0

Short

As I mentioned in comment and @Thor also pointed, you need to change the PHP version on your host to at least 7.0, preferable to highest possible. Check for Googles API requirements in their docs which PHP version is minimum.

Details

Argument type declarations and return type declarations were introduced (finally!) in PHP ver. 7.0 see what else.

So this is valid code for PHP 7.x

function describe_type($input): string
{
    return Utils::describeType($input);
}

function headers_from_lines(iterable $lines): array
{
    return Utils::headersFromLines($lines);
}

as this would be valid in PHP 5.x

function describe_type($input)
{
    return Utils::describeType($input);
}

function headers_from_lines($lines)
{
    return Utils::headersFromLines($lines);
}

find the difference.

biesior
  • 55,576
  • 10
  • 125
  • 182