Skip to content

Instantly share code, notes, and snippets.

@vivirenremoto
Created May 4, 2020 15:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vivirenremoto/f691a8cf4e7b73123dc418426d577830 to your computer and use it in GitHub Desktop.
Save vivirenremoto/f691a8cf4e7b73123dc418426d577830 to your computer and use it in GitHub Desktop.
Usar Google Spreadsheets como API
<?php
$id = '1ERm4xxxTNLeZOStU5vG4KdVIZMDp3rT_xxxfJsdck';
$url = 'https://spreadsheets.google.com/feeds/list/' . $id . '/od6/public/values?alt=json-in-script';
$json = file_get_contents($url);
$json = str_replace( array('gdata.io.handleScriptLoaded(',');'), '', $json);
$json = json_decode($json);
$items = array();
foreach( $json->feed->entry as $cols ){
$cols = (array)$cols;
$props = array();
foreach( $cols as $key => $col ){
if( strstr($key, 'gsx$') ){
$key = str_replace('gsx$', '', $key);
$val = $col->{'$t'};
$props[$key] = $val;
}
}
$items[] = $props;
}
echo json_encode( array('data' => $items) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment