I have on my local server with wamp a php file where I have a code to get the data of a form and send them to the google sheet with a google sheet library. But when I take these files the library and the php code to the external server of my web, when I make a test the php page goes blank and does not work since I do not enter the records to the Google sheet.
I leave the code:
<?php
// Composer's auto-loading functionality
require "vendor/autoload.php";
use Google\Spreadsheet\DefaultServiceRequest;
use Google\Spreadsheet\ServiceRequestFactory;
$nombreAplicacion = "PhpSheet";
$direccionCorreo = "[email protected]";
$idCliente = "3a5bbd2c9ada9a0f85e8fc1516157400c754d6fa";
// Nombre del SpreadSheet creada
$nombreSpreahSheet = "Php Sheet volcado";
// Nombre de hoja de cálculo
$hojaCalculo = "Hoja 2";
$scope = array('https://spreadsheets.google.com/feeds');
// Inicializamos Google Client
$client = new Google_Client();
$client->setApplicationName($nombreAplicacion);
$client->setClientId($idCliente);
// credenciales, scope y archivo p12. Agregar el correcto Path al archivo p12
$cred = new Google_Auth_AssertionCredentials(
$direccionCorreo,
$scope,
file_get_contents('PhpSheet-3a5bbd2c9ada.p12')
);
$client->setAssertionCredentials($cred);
// si expiro el access token generamos otro
if($client->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
// Obtenemos el access token
$obj_token = json_decode($client->getAccessToken());
$accessToken = $obj_token->access_token;
// Inicializamos google-spreadsheet-client
$serviceRequest = new DefaultServiceRequest($accessToken);
ServiceRequestFactory::setInstance($serviceRequest);
//Obtenemos los Spreadsheets disponibles para las credenciales actuales
$spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
$spreadsheetFeed = $spreadsheetService->getSpreadsheets();
// Obtenemos la spreadsheet por su nombre
$spreadsheet = $spreadsheetFeed->getByTitle($nombreSpreahSheet);
// Obtenemos las hojas de cálculo de la spreadsheet obetenida
$worksheetFeed = $spreadsheet->getWorksheets();
// Obtenemos la hoja de cálculo por su nombre
$worksheet = $worksheetFeed->getByTitle($hojaCalculo);
$listFeed = $worksheet->getListFeed();
$dataAgregar = array('nombre' => $_SESSION['nombre'],
'email' => $_SESSION['email'],
'telefono' => $_SESSION['phone'],
'mensaje' => $_SESSION['mensaje'],
'landing' => $landingP
);
// Agregar datos
$listFeed->insert($dataAgregar);
echo ('Se han insertado correctamente los registros')
?>