fix console api for php insert data into google sheets
Budget: $30 – $250 USD
Hello,
I had php code inserting data to google sheets for 5 years, sudently stopped working. I cant fight coder who did it, it was using his gmail and his credentials. I have followed some video to use my gmail account and create api/credentials but not working.
Code in sales.php:
/*---------- Add Sale Item Data In Google Spreadsheets ---------*/
$sale_itme = $this->mdl_finance->get_expense_items($finance_id, 'fp_sale_items');
$customer_id = $this->mdl_common->get_record('fp_sale_entry', array('finance_id' => $finance_id, 'account_id' => $this->session->userdata("account_id"), 'is_del' => 0))->row()->customer_id;
$customer_detail = $this->mdl_common->get_record('fp_vendor_and_customer_group', array('id' => $customer_id, 'account_id' => $this->session->userdata("account_id"), 'is_vendor_or_customer' => 2, 'is_del' => 0))->row_array();
$client_name = $customer_detail['name'];
$city_state = '';
if($customer_detail['city'] != '' && $customer_detail['area'] != '')
{
$city_state = $customer_detail['city'].' - '.$customer_detail['area'];
}
elseif($customer_detail['city'] != '')
{
$city_state = $customer_detail['city'];
}
elseif($customer_detail['area'] != '')
{
$city_state = $customer_detail['city'];
}
$task_detail = $this->mdl_common->get_record('fp_task', array('task_id' => $inserted_task_id, 'finance_id' => $finance_id, 'account_id' => $this->session->userdata("account_id"), 'task_type' => '-1', 'is_del' => 0))->row_array();
$date = date('d/m', strtotime($task_detail['creation_datetime']));
$ticket_id1 = $task_detail['ticket_id'];
$results = Array();
foreach ($sale_itme as $val)
{
$product_name = $val['item_name'];
$product_code = $val['item_code'].''.$val['item_num'];
$net_quantity = $val['net_quantity'];
$results[] = Array(
'0' => '',
'1' => $date,
'2' => $inserted_task_id,
'3' => $ticket_id1,
'4' => $client_name,
'5' => '',
'6' => $city_state,
'7' => $product_code,
'8' => $product_name,
'9' => $net_quantity,
);
}
$client = $this->mdl_common->getClient();
$service = new Google_Service_Sheets($client);
$spreadsheetId = GOOGLE_SPREADSHEET_KEY;
$ranges = SHEET_NAME;
$result = $service->spreadsheets_values->get($spreadsheetId, $ranges);
$numRows = $result->getValues() != null ? count($result->getValues()) : 0;
if($numRows != 0) {
$num_row = $numRows + 1;
$range = 'PENDENTES!A'.$num_row.':J'.$num_row;
}
else {
$range = 'PENDENTES!A:J';
}
$requestBody = new Google_Service_Sheets_ValueRange(array(
'majorDimension' => 'ROWS',
'values' => $results
));
$params = ['valueInputOption' => 'USER_ENTERED'];
$ins = ['insertDataOption' => 'INSERT_ROWS'];
$response = $service->spreadsheets_values->append($spreadsheetId, $range, $requestBody, $params, $ins);
//echo '<pre>', var_export($response, true), '</pre>', "\n";die;
/*---------- END CODE ---------*/
code in constant.php:
/*------- Google Spreadsheets Key/SheetName --------*/
//Google Login Live Access
//Email : mjohntest**@gmail
//Pwd : *****
define('GOOGLE_SPREADSHEET_KEY','14rVYyiimHbrFlZhM71GPiieFFbgPF8Ktmdryr1ALgzo');
define('SHEET_NAME','PENDENTES!B:J');
I followed this video https://www.youtube.com/watch?v=zoufwxZjr0c to create api and credentials on my gmail account.
attached googlesheet picture and console
I had php code inserting data to google sheets for 5 years, sudently stopped working. I cant fight coder who did it, it was using his gmail and his credentials. I have followed some video to use my gmail account and create api/credentials but not working.
Code in sales.php:
/*---------- Add Sale Item Data In Google Spreadsheets ---------*/
$sale_itme = $this->mdl_finance->get_expense_items($finance_id, 'fp_sale_items');
$customer_id = $this->mdl_common->get_record('fp_sale_entry', array('finance_id' => $finance_id, 'account_id' => $this->session->userdata("account_id"), 'is_del' => 0))->row()->customer_id;
$customer_detail = $this->mdl_common->get_record('fp_vendor_and_customer_group', array('id' => $customer_id, 'account_id' => $this->session->userdata("account_id"), 'is_vendor_or_customer' => 2, 'is_del' => 0))->row_array();
$client_name = $customer_detail['name'];
$city_state = '';
if($customer_detail['city'] != '' && $customer_detail['area'] != '')
{
$city_state = $customer_detail['city'].' - '.$customer_detail['area'];
}
elseif($customer_detail['city'] != '')
{
$city_state = $customer_detail['city'];
}
elseif($customer_detail['area'] != '')
{
$city_state = $customer_detail['city'];
}
$task_detail = $this->mdl_common->get_record('fp_task', array('task_id' => $inserted_task_id, 'finance_id' => $finance_id, 'account_id' => $this->session->userdata("account_id"), 'task_type' => '-1', 'is_del' => 0))->row_array();
$date = date('d/m', strtotime($task_detail['creation_datetime']));
$ticket_id1 = $task_detail['ticket_id'];
$results = Array();
foreach ($sale_itme as $val)
{
$product_name = $val['item_name'];
$product_code = $val['item_code'].''.$val['item_num'];
$net_quantity = $val['net_quantity'];
$results[] = Array(
'0' => '',
'1' => $date,
'2' => $inserted_task_id,
'3' => $ticket_id1,
'4' => $client_name,
'5' => '',
'6' => $city_state,
'7' => $product_code,
'8' => $product_name,
'9' => $net_quantity,
);
}
$client = $this->mdl_common->getClient();
$service = new Google_Service_Sheets($client);
$spreadsheetId = GOOGLE_SPREADSHEET_KEY;
$ranges = SHEET_NAME;
$result = $service->spreadsheets_values->get($spreadsheetId, $ranges);
$numRows = $result->getValues() != null ? count($result->getValues()) : 0;
if($numRows != 0) {
$num_row = $numRows + 1;
$range = 'PENDENTES!A'.$num_row.':J'.$num_row;
}
else {
$range = 'PENDENTES!A:J';
}
$requestBody = new Google_Service_Sheets_ValueRange(array(
'majorDimension' => 'ROWS',
'values' => $results
));
$params = ['valueInputOption' => 'USER_ENTERED'];
$ins = ['insertDataOption' => 'INSERT_ROWS'];
$response = $service->spreadsheets_values->append($spreadsheetId, $range, $requestBody, $params, $ins);
//echo '<pre>', var_export($response, true), '</pre>', "\n";die;
/*---------- END CODE ---------*/
code in constant.php:
/*------- Google Spreadsheets Key/SheetName --------*/
//Google Login Live Access
//Email : mjohntest**@gmail
//Pwd : *****
define('GOOGLE_SPREADSHEET_KEY','14rVYyiimHbrFlZhM71GPiieFFbgPF8Ktmdryr1ALgzo');
define('SHEET_NAME','PENDENTES!B:J');
I followed this video https://www.youtube.com/watch?v=zoufwxZjr0c to create api and credentials on my gmail account.
attached googlesheet picture and console