Skip to content
Snippets Groups Projects
Commit eeaa9f27 authored by Karl Shea's avatar Karl Shea
Browse files

Issue #3236814 by slayne40, KarlShea, greenjuls: Google Sheets v4 API

parent 442447a9
No related branches found
No related tags found
No related merge requests found
......@@ -7,10 +7,9 @@ source:
data_fetcher_plugin: http
data_parser_plugin: google_sheets
# The feed file for the spreadsheet. The Google Spreadsheet should be either “Public” or set to “Anyone with link can
# view” in order for the feed to work. Note that the <SHEET> param is the order of the tabs and WILL change if the
# tabs are re-ordered.
# Template: 'https://spreadsheets.google.com/feeds/list/<KEY>/<SHEET>/public/values?alt=json'
urls: 'http://spreadsheets.google.com/feeds/list/1spS1BeUIzxR1KrGK2kKzAoiFZii6vBHyLx_SA0Sb89M/4/public/values?alt=json'
# view” in order for the feed to work.
# Template: 'https://sheets.googleapis.com/v4/spreadsheets/<SHEET>/values/<TAB>?key=<KEY>'
urls: 'https://sheets.googleapis.com/v4/spreadsheets/1spS1BeUIzxR1KrGK2kKzAoiFZii6vBHyLx_SA0Sb89M/values/Block?key=<KEY>'
# Under 'fields', we list the data items to be imported. The first level keys
# are the source field names we want to populate (the names to be used as
# sources in the process configuration below). For each field we're importing,
......
......@@ -7,10 +7,9 @@ source:
data_fetcher_plugin: http
data_parser_plugin: google_sheets
# The feed file for the spreadsheet. The Google Spreadsheet should be either “Public” or set to “Anyone with link can
# view” in order for the feed to work. Note that the <SHEET> param is the order of the tabs and WILL change if the
# tabs are re-ordered.
# Template: 'https://spreadsheets.google.com/feeds/list/<KEY>/<SHEET>/public/values?alt=json'
urls: 'http://spreadsheets.google.com/feeds/list/1spS1BeUIzxR1KrGK2kKzAoiFZii6vBHyLx_SA0Sb89M/1/public/values?alt=json'
# view” in order for the feed to work.
# Template: 'https://sheets.googleapis.com/v4/spreadsheets/<SHEET>/values/<TAB>?key=<KEY>'
urls: 'https://sheets.googleapis.com/v4/spreadsheets/1spS1BeUIzxR1KrGK2kKzAoiFZii6vBHyLx_SA0Sb89M/values/Menu%20Links?key=<KEY>'
# Under 'fields', we list the data items to be imported. The first level keys
# are the source field names we want to populate (the names to be used as
# sources in the process configuration below). For each field we're importing,
......
......@@ -7,10 +7,9 @@ source:
data_fetcher_plugin: http
data_parser_plugin: google_sheets
# The feed file for the spreadsheet. The Google Spreadsheet should be either “Public” or set to “Anyone with link can
# view” in order for the feed to work. Note that the <SHEET> param is the order of the tabs and WILL change if the
# tabs are re-ordered.
# Template: 'https://spreadsheets.google.com/feeds/list/<KEY>/<SHEET>/public/values?alt=json'
urls: 'http://spreadsheets.google.com/feeds/list/1spS1BeUIzxR1KrGK2kKzAoiFZii6vBHyLx_SA0Sb89M/3/public/values?alt=json'
# view” in order for the feed to work.
# Template: 'https://sheets.googleapis.com/v4/spreadsheets/<SHEET>/values/<TAB>?key=<KEY>'
urls: 'https://sheets.googleapis.com/v4/spreadsheets/1spS1BeUIzxR1KrGK2kKzAoiFZii6vBHyLx_SA0Sb89M/values/Game?key=<KEY>'
# Under 'fields', we list the data items to be imported. The first level keys
# are the source field names we want to populate (the names to be used as
# sources in the process configuration below). For each field we're importing,
......
......@@ -5,8 +5,8 @@ source:
plugin: url
data_fetcher_plugin: http
data_parser_plugin: google_sheets
# Template: 'https://spreadsheets.google.com/feeds/list/<KEY>/<SHEET>/public/values?alt=json'
urls: 'http://spreadsheets.google.com/feeds/list/1spS1BeUIzxR1KrGK2kKzAoiFZii6vBHyLx_SA0Sb89M/3/public/values?alt=json'
# Template: 'https://sheets.googleapis.com/v4/spreadsheets/<SHEET>/values/<TAB>?key=<KEY>'
urls: 'https://sheets.googleapis.com/v4/spreadsheets/1spS1BeUIzxR1KrGK2kKzAoiFZii6vBHyLx_SA0Sb89M/values/Game?key=<KEY>'
# Under 'fields', we list the data items to be imported. The first level keys
# are the source field names we want to populate (the names to be used as
# sources in the process configuration below). For each field we're importing,
......
......@@ -7,10 +7,9 @@ source:
data_fetcher_plugin: http
data_parser_plugin: google_sheets
# The feed file for the spreadsheet. The Google Spreadsheet should be either “Public” or set to “Anyone with link can
# view” in order for the feed to work. Note that the <SHEET> param is the order of the tabs and WILL change if the
# tabs are re-ordered.
# Template: 'https://spreadsheets.google.com/feeds/list/<KEY>/<SHEET>/public/values?alt=json'
urls: 'http://spreadsheets.google.com/feeds/list/1spS1BeUIzxR1KrGK2kKzAoiFZii6vBHyLx_SA0Sb89M/2/public/values?alt=json'
# view” in order for the feed to work.
# Template: 'https://sheets.googleapis.com/v4/spreadsheets/<SHEET>/values/<TAB>?key=<KEY>'
urls: 'https://sheets.googleapis.com/v4/spreadsheets/1spS1BeUIzxR1KrGK2kKzAoiFZii6vBHyLx_SA0Sb89M/values/Page?key=<KEY>'
# Under 'fields', we list the data items to be imported. The first level keys
# are the source field names we want to populate (the names to be used as
# sources in the process configuration below). For each field we're importing,
......
......@@ -5,8 +5,8 @@ source:
plugin: url
data_fetcher_plugin: http
data_parser_plugin: google_sheets
# Template: 'https://spreadsheets.google.com/feeds/list/<KEY>/<SHEET>/public/values?alt=json'
urls: 'http://spreadsheets.google.com/feeds/list/1spS1BeUIzxR1KrGK2kKzAoiFZii6vBHyLx_SA0Sb89M/2/public/values?alt=json'
# Template: 'https://sheets.googleapis.com/v4/spreadsheets/<SHEET>/values/<TAB>?key=<KEY>'
urls: 'https://sheets.googleapis.com/v4/spreadsheets/1spS1BeUIzxR1KrGK2kKzAoiFZii6vBHyLx_SA0Sb89M/values/Page?key=<KEY>'
# Under 'fields', we list the data items to be imported. The first level keys
# are the source field names we want to populate (the names to be used as
# sources in the process configuration below). For each field we're importing,
......
......@@ -38,26 +38,20 @@ class GoogleSheets extends Json implements ContainerFactoryPluginInterface {
// correct values.
try {
$response = $this->getDataFetcherPlugin()->getResponseContent($url);
// Response returns json wrapped in a function call, first 47 and last 2 chars.
$response = substr($response, 47, (strlen($response) - 47 - 2));
// The TRUE setting means decode the response into an associative array.
$array = json_decode($response, TRUE);
// For Google Sheets, the actual row data lives under table->rows.
if (isset($array['table']) && isset($array['table']['rows'])) {
if (isset($array['table']['cols']) && $array['table']['parsedNumHeaders'] > 0) {
// Set headers based on column labels.
$columns = array_column($array['table']['cols'], 'label');
} else {
// Set headers from first row.
$first_row = array_shift($array['table']['rows']);
$columns = array_column($first_row['c'], 'v');
}
if (isset($array['values'])) {
// Set headers from first row.
$first_row = array_shift($array['values']);
$columns = $first_row;
$this->headers = array_map(function($col) {
return strtolower($col);
}, $columns);
$array = $array['table']['rows'];
$array = $array['values'];
} else {
$array = [];
}
......@@ -78,10 +72,10 @@ class GoogleSheets extends Json implements ContainerFactoryPluginInterface {
foreach ($this->fieldSelectors() as $field_name => $selector) {
// Actual values are stored in c[<column index>]['v'].
$column_index = array_search(strtolower($selector), $this->headers);
if ($column_index >= 0) {
$this->currentItem[$field_name] = $current['c'][$column_index]['v'];
if ($column_index >= 0 && isset($current[$column_index])) {
$this->currentItem[$field_name] = $current[$column_index];
} else {
$this->currentItem[$field_name] = NULL;
$this->currentItem[$field_name] = '';
}
}
$this->iterator->next();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment