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);
Solved it. The problem was PHP version. I switched to 7.2 and seems to work perfect!