- First Clone this project
- make migration
- In Google Cloud Console Steps :
- Enable Google Sheets API
- Create a Service Account (IAM & Admin → Service Accounts → Create → Key → JSON)
- Download JSON (it will contain "type": "service_account")
- Save that JSON in storage/google/credentials.json (Note: Available credentials.json in this project is sample create your own json file and store that place)
- Create New SpreadSheet and add data for example : https://docs.google.com/spreadsheets/d/1efhCwABHI5KKXisqFrdgFIWpeSotikgO7c3uWqlQTzo/edit?gid=0#gid=0
- get that SpreadsheetId and Save into File : SyncGoogleSheet.php
- If you want to Run via Schedular then Set in Console/Kernel.php
- Above 8 Steps are common
- Now in SpreadSheet go to Extensions -> App Script
function syncEntireSheet() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var data = sheet.getDataRange().getValues(); // all rows including header
// Optionally remove header row
data.shift();
var payload = {
rows: data
};
var options = {
method: "post",
contentType: "application/json",
payload: JSON.stringify(payload)
};
var response = UrlFetchApp.fetch("<SITE_URL>/api/google-sheet-sync-all?sheet_id=<SHEET_ID>", options);
Logger.log(response.getContentText());
}
- Now deploy that script in App Script and Set Schedular -> Add Trigger -> Save
- So when user make changes it will directly reflect into database without laravel queue.