Thanks for your answer Eric. I made the spreadsheet publicly readable, but my code doesn't work, nor when I put the API key in the API link : <script src= "https://apis.google.com/js/client.js?key=my-api-key?onload=loadAPI" ></script>
Do you know where the key must be put in the code ? The code worked when I used the OAuth authentication used here <https://developers.google.com/sheets/quickstart/js#step_2_set_up_the_sample>, but it asks the user for approval and I don't need this, since we just read a public sheet. Do you have an idea of how to make this simple code work ? :) Le mardi 14 juin 2016 21:11:04 UTC+2, Eric Koleda a écrit : > > 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.
