I don't think service accounts work with the JavaScript API, nor do you 
seem to be using it. If you just make the spreadsheet publicly-readable 
then it should work with just an API key.

- Eric

On Monday, June 13, 2016 at 2:02:02 AM UTC-4, Victor wrote:
>
> Hi,
>
> My goal is simply to read cells in a Google sheet of my account and 
> display them in a html block of a Wordpress website so that anyone can see 
> the values of the cells.
>
> I have set up a "service account" on *console.developers.google.com*, and 
> my code is the following, but it doesn't work :
>
>      
>  <html>
>       <head>
>       <script type="text/javascript">
>         
>             function loadSheetsAPI() {
>         gapi.client.setApiKey('my-api-key');
>                 var discoveryUrl =
>                 'https://sheets.googleapis.com/$discovery/rest?version=v4'
> ;
>                 gapi.client.load(discoveryUrl).then(getCounter);
>             }
>             
>             function getCounter() {
>                 gapi.client.sheets.spreadsheets.values.get({
>                   spreadsheetId: 'my-sheet-id',
>                   range: '!H2:I2',
>                 }).then(function(response) {
>                   var range = response.result;
>                   if (range.values.length > 0) {
>                     for (i = 0; i < range.values.length; i++) {
>                       var row = range.values[i];
>                       appendPre(row[1] + '\n' + row[0]);
>                     }
>                   } else {
>                     appendPre('No data found');
>                   }
>                 }, function(response) {
>                   appendPre('Error: ' + response.result.error.message);
>                 });
>               }
>               
>             function appendPre(message) {
>                 var pre = document.getElementById('output');
>                 var textContent = document.createTextNode(message + '\n');
>                 pre.appendChild(textContent);
>               }
>              
>         </script>
>         <script src="
> https://apis.google.com/js/client.js?onload=loadSheetsAPI";>
>         </script>
>       </head>
>       <body>
>     <pre id="output"></pre>
>     </body>
>     </html>
>
>
>
> Could someone help me please ?
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Spreadsheets API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to