0

I'm working on a project where I have to make a server to server app with PHP.

The concept is : the company uploads bills to Google drive and the users use the website to retrieve their bills. First of all I didn't use a composer to the server because I have no permission to install. So I downloaded the libs and uploaded to server with ftp. Then I created a G Suite Google account and followed the instructions from their guide https://developers.google.com/api-client-library/php/auth/service-accounts.

The weird thing is if var_dump(service) after $results = $service->files , I see that the verification for the client has be done. When I try to use the api with $results = $service->files->listFiles($optParams); the page doesn't respond. Im really confused with this.

<?php
session_start();
require_once "vendor/autoload.php";
require 'init.php';

putenv('GOOGLE_APPLICATION_CREDENTIALS=service.json');

$client = getClient();
$service = new Google_Service_Drive($client);

function getClient() {
    $client = new Google_Client();
    $client->useApplicationDefaultCredentials();
    return $client;
}
 $optParams = array(
    'pageSize' => 5,
    'fields' => 'files(webViewLink, name , parents, id)'
);

$results = $service->files->listFiles($optParams);
droidBomb
  • 850
  • 5
  • 8
K. Efkas
  • 21
  • 5
  • Could you provide the logs? – abielita Nov 06 '18 at 15:28
  • [06-Nov-2018 16:21:23 UTC] PHP Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in /home/obiorange/public_html/nera/google-api-php-client-2.2.2/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 84 – K. Efkas Nov 06 '18 at 16:24
  • i found that this error appears because 'class' is name of a constant , only PHP 5.5 doesnt use it as a tag . My PHP version is 5.6.30. – K. Efkas Nov 06 '18 at 17:02

1 Answers1

0

Solved it. The problem was PHP version. I switched to 7.2 and seems to work perfect!

K. Efkas
  • 21
  • 5