using an http request to update google spreadsheet












2















Trying to set up a spreadsheet to take in data via an http post. To test it, I set up a simple python script to just send an http request. I dont want to use a specific google api on python or somewhere else, because I want some other people to be able to simply send a request how they would like. So, In my google script I just have:



function doPost(e){
sheet = SpreadsheetApp.getActiveSheet();
range = sheet.getRange(1, 1)
ange.setValue(e.text)
}


In python I simply have:



import requests

if __name__== "__main__":
params = {'Authorization': "Bearer [token]",
'contentType': 'application/json',
'text': "is working?"}
r = requests.post("https://script.google.com/macros/s/[uniquekey]/exec", params)
print(r.status_code, r.reason)


All I get is




"401 Unauthorized"




I've also tried sending this over python as well as running JS in a webserver and through chrome (which i guessed raised security issues). everything gave me the same response. I'm sure I'm just not authorizing properly, but I havent been able to find the correct way to do it. thanks in advance. I'm sure theres some other issues too, but I cant seem to even get access.










share|improve this question





























    2















    Trying to set up a spreadsheet to take in data via an http post. To test it, I set up a simple python script to just send an http request. I dont want to use a specific google api on python or somewhere else, because I want some other people to be able to simply send a request how they would like. So, In my google script I just have:



    function doPost(e){
    sheet = SpreadsheetApp.getActiveSheet();
    range = sheet.getRange(1, 1)
    ange.setValue(e.text)
    }


    In python I simply have:



    import requests

    if __name__== "__main__":
    params = {'Authorization': "Bearer [token]",
    'contentType': 'application/json',
    'text': "is working?"}
    r = requests.post("https://script.google.com/macros/s/[uniquekey]/exec", params)
    print(r.status_code, r.reason)


    All I get is




    "401 Unauthorized"




    I've also tried sending this over python as well as running JS in a webserver and through chrome (which i guessed raised security issues). everything gave me the same response. I'm sure I'm just not authorizing properly, but I havent been able to find the correct way to do it. thanks in advance. I'm sure theres some other issues too, but I cant seem to even get access.










    share|improve this question



























      2












      2








      2


      1






      Trying to set up a spreadsheet to take in data via an http post. To test it, I set up a simple python script to just send an http request. I dont want to use a specific google api on python or somewhere else, because I want some other people to be able to simply send a request how they would like. So, In my google script I just have:



      function doPost(e){
      sheet = SpreadsheetApp.getActiveSheet();
      range = sheet.getRange(1, 1)
      ange.setValue(e.text)
      }


      In python I simply have:



      import requests

      if __name__== "__main__":
      params = {'Authorization': "Bearer [token]",
      'contentType': 'application/json',
      'text': "is working?"}
      r = requests.post("https://script.google.com/macros/s/[uniquekey]/exec", params)
      print(r.status_code, r.reason)


      All I get is




      "401 Unauthorized"




      I've also tried sending this over python as well as running JS in a webserver and through chrome (which i guessed raised security issues). everything gave me the same response. I'm sure I'm just not authorizing properly, but I havent been able to find the correct way to do it. thanks in advance. I'm sure theres some other issues too, but I cant seem to even get access.










      share|improve this question
















      Trying to set up a spreadsheet to take in data via an http post. To test it, I set up a simple python script to just send an http request. I dont want to use a specific google api on python or somewhere else, because I want some other people to be able to simply send a request how they would like. So, In my google script I just have:



      function doPost(e){
      sheet = SpreadsheetApp.getActiveSheet();
      range = sheet.getRange(1, 1)
      ange.setValue(e.text)
      }


      In python I simply have:



      import requests

      if __name__== "__main__":
      params = {'Authorization': "Bearer [token]",
      'contentType': 'application/json',
      'text': "is working?"}
      r = requests.post("https://script.google.com/macros/s/[uniquekey]/exec", params)
      print(r.status_code, r.reason)


      All I get is




      "401 Unauthorized"




      I've also tried sending this over python as well as running JS in a webserver and through chrome (which i guessed raised security issues). everything gave me the same response. I'm sure I'm just not authorizing properly, but I havent been able to find the correct way to do it. thanks in advance. I'm sure theres some other issues too, but I cant seem to even get access.







      python google-apps-script web-applications authorization http-status-code-401






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 '18 at 22:25









      TheMaster

      10.1k3835




      10.1k3835










      asked Nov 19 '18 at 21:20









      BastiatBastiat

      1931214




      1931214
























          1 Answer
          1






          active

          oldest

          votes


















          2














          How about this modification?



          Modified script:



          In this modified script supposes as follows.




          • Web Apps is deployed as



            • Execute the app as is Me


            • Who has access to the app is Only myself or Anyone



          • Your access token can be used for accessing to your Web Apps.
            If your access token cannot be used for it, please try to set the Web Apps as follows.
            - Execute the app as is Me
            - Who has access to the app is Anyone, even anonymous
            - In this setting, you can access to Web Apps without the access token.


          Python:



          import requests

          if __name__== "__main__":
          params = {
          'text': "is working?",
          }
          headers = {
          'Authorization': "Bearer [token]",
          }
          r = requests.post("https://script.google.com/macros/s/[uniquekey]/exec", data=params, headers=headers)
          print(r.status_code, r.reason)


          Note:


          • Please put the access token to the header.


          Google Apps Script:



          When you modified your script, please redeploy as new version. By this, the latest script is reflected to the Web Apps.



          function doPost(e) {
          const sheet = SpreadsheetApp.getActiveSheet();
          const range = sheet.getRange(1, 1);
          range.setValue(e.parameter.text);
          return ContentService.createTextOutput("Done.");
          }


          Note:


          • By returning ContentService.createTextOutput(), Web Apps returns the status code of 200.

          • You can retrieve the value of 'text': "is working?" as e.parameter.text.

          • When you use SpreadsheetApp.getActiveSheet(), the value of e.parameter.text is put to the 1st page of Spreadsheet.


          References:




          • Web Apps

          • ContentService


          In my environment, I could confirm that this modification worked. But if in your environment, this modified scripts didn't work, I'm sorry.






          share|improve this answer
























          • thank you very much. changing the setting to "even anonymous" did work. I am still doing something wrong with the authorization token. I probably just dont fully know how to set that up through the google api auth system but this gets me on my way to setting up the sheet as I need to and I can work on the auth stuff later. thanks again.

            – Bastiat
            Nov 20 '18 at 15:12











          • @Bastiat Thank you for replying. I'm glad a part of your issue was resolved. About the authorization, for example, is this quickstart useful for you? developers.google.com/drive/api/v3/quickstart/python In this script, OAuth2 process is used.

            – Tanaike
            Nov 20 '18 at 22:16











          • were it just a project on my part, yea, I would just be using that. I had hoped to be able to do this just via standard requests without the library because I was just using python for testing while the actual use case would be push requests sent from a powershell environment. So I was trying to avoid those kinds of dependent libraries. Maybe that was a valid goal, maybe not.

            – Bastiat
            Nov 21 '18 at 14:52











          • @Bastiat Thank you for the additional information.

            – Tanaike
            Nov 21 '18 at 23:28











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53382802%2fusing-an-http-request-to-update-google-spreadsheet%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          How about this modification?



          Modified script:



          In this modified script supposes as follows.




          • Web Apps is deployed as



            • Execute the app as is Me


            • Who has access to the app is Only myself or Anyone



          • Your access token can be used for accessing to your Web Apps.
            If your access token cannot be used for it, please try to set the Web Apps as follows.
            - Execute the app as is Me
            - Who has access to the app is Anyone, even anonymous
            - In this setting, you can access to Web Apps without the access token.


          Python:



          import requests

          if __name__== "__main__":
          params = {
          'text': "is working?",
          }
          headers = {
          'Authorization': "Bearer [token]",
          }
          r = requests.post("https://script.google.com/macros/s/[uniquekey]/exec", data=params, headers=headers)
          print(r.status_code, r.reason)


          Note:


          • Please put the access token to the header.


          Google Apps Script:



          When you modified your script, please redeploy as new version. By this, the latest script is reflected to the Web Apps.



          function doPost(e) {
          const sheet = SpreadsheetApp.getActiveSheet();
          const range = sheet.getRange(1, 1);
          range.setValue(e.parameter.text);
          return ContentService.createTextOutput("Done.");
          }


          Note:


          • By returning ContentService.createTextOutput(), Web Apps returns the status code of 200.

          • You can retrieve the value of 'text': "is working?" as e.parameter.text.

          • When you use SpreadsheetApp.getActiveSheet(), the value of e.parameter.text is put to the 1st page of Spreadsheet.


          References:




          • Web Apps

          • ContentService


          In my environment, I could confirm that this modification worked. But if in your environment, this modified scripts didn't work, I'm sorry.






          share|improve this answer
























          • thank you very much. changing the setting to "even anonymous" did work. I am still doing something wrong with the authorization token. I probably just dont fully know how to set that up through the google api auth system but this gets me on my way to setting up the sheet as I need to and I can work on the auth stuff later. thanks again.

            – Bastiat
            Nov 20 '18 at 15:12











          • @Bastiat Thank you for replying. I'm glad a part of your issue was resolved. About the authorization, for example, is this quickstart useful for you? developers.google.com/drive/api/v3/quickstart/python In this script, OAuth2 process is used.

            – Tanaike
            Nov 20 '18 at 22:16











          • were it just a project on my part, yea, I would just be using that. I had hoped to be able to do this just via standard requests without the library because I was just using python for testing while the actual use case would be push requests sent from a powershell environment. So I was trying to avoid those kinds of dependent libraries. Maybe that was a valid goal, maybe not.

            – Bastiat
            Nov 21 '18 at 14:52











          • @Bastiat Thank you for the additional information.

            – Tanaike
            Nov 21 '18 at 23:28
















          2














          How about this modification?



          Modified script:



          In this modified script supposes as follows.




          • Web Apps is deployed as



            • Execute the app as is Me


            • Who has access to the app is Only myself or Anyone



          • Your access token can be used for accessing to your Web Apps.
            If your access token cannot be used for it, please try to set the Web Apps as follows.
            - Execute the app as is Me
            - Who has access to the app is Anyone, even anonymous
            - In this setting, you can access to Web Apps without the access token.


          Python:



          import requests

          if __name__== "__main__":
          params = {
          'text': "is working?",
          }
          headers = {
          'Authorization': "Bearer [token]",
          }
          r = requests.post("https://script.google.com/macros/s/[uniquekey]/exec", data=params, headers=headers)
          print(r.status_code, r.reason)


          Note:


          • Please put the access token to the header.


          Google Apps Script:



          When you modified your script, please redeploy as new version. By this, the latest script is reflected to the Web Apps.



          function doPost(e) {
          const sheet = SpreadsheetApp.getActiveSheet();
          const range = sheet.getRange(1, 1);
          range.setValue(e.parameter.text);
          return ContentService.createTextOutput("Done.");
          }


          Note:


          • By returning ContentService.createTextOutput(), Web Apps returns the status code of 200.

          • You can retrieve the value of 'text': "is working?" as e.parameter.text.

          • When you use SpreadsheetApp.getActiveSheet(), the value of e.parameter.text is put to the 1st page of Spreadsheet.


          References:




          • Web Apps

          • ContentService


          In my environment, I could confirm that this modification worked. But if in your environment, this modified scripts didn't work, I'm sorry.






          share|improve this answer
























          • thank you very much. changing the setting to "even anonymous" did work. I am still doing something wrong with the authorization token. I probably just dont fully know how to set that up through the google api auth system but this gets me on my way to setting up the sheet as I need to and I can work on the auth stuff later. thanks again.

            – Bastiat
            Nov 20 '18 at 15:12











          • @Bastiat Thank you for replying. I'm glad a part of your issue was resolved. About the authorization, for example, is this quickstart useful for you? developers.google.com/drive/api/v3/quickstart/python In this script, OAuth2 process is used.

            – Tanaike
            Nov 20 '18 at 22:16











          • were it just a project on my part, yea, I would just be using that. I had hoped to be able to do this just via standard requests without the library because I was just using python for testing while the actual use case would be push requests sent from a powershell environment. So I was trying to avoid those kinds of dependent libraries. Maybe that was a valid goal, maybe not.

            – Bastiat
            Nov 21 '18 at 14:52











          • @Bastiat Thank you for the additional information.

            – Tanaike
            Nov 21 '18 at 23:28














          2












          2








          2







          How about this modification?



          Modified script:



          In this modified script supposes as follows.




          • Web Apps is deployed as



            • Execute the app as is Me


            • Who has access to the app is Only myself or Anyone



          • Your access token can be used for accessing to your Web Apps.
            If your access token cannot be used for it, please try to set the Web Apps as follows.
            - Execute the app as is Me
            - Who has access to the app is Anyone, even anonymous
            - In this setting, you can access to Web Apps without the access token.


          Python:



          import requests

          if __name__== "__main__":
          params = {
          'text': "is working?",
          }
          headers = {
          'Authorization': "Bearer [token]",
          }
          r = requests.post("https://script.google.com/macros/s/[uniquekey]/exec", data=params, headers=headers)
          print(r.status_code, r.reason)


          Note:


          • Please put the access token to the header.


          Google Apps Script:



          When you modified your script, please redeploy as new version. By this, the latest script is reflected to the Web Apps.



          function doPost(e) {
          const sheet = SpreadsheetApp.getActiveSheet();
          const range = sheet.getRange(1, 1);
          range.setValue(e.parameter.text);
          return ContentService.createTextOutput("Done.");
          }


          Note:


          • By returning ContentService.createTextOutput(), Web Apps returns the status code of 200.

          • You can retrieve the value of 'text': "is working?" as e.parameter.text.

          • When you use SpreadsheetApp.getActiveSheet(), the value of e.parameter.text is put to the 1st page of Spreadsheet.


          References:




          • Web Apps

          • ContentService


          In my environment, I could confirm that this modification worked. But if in your environment, this modified scripts didn't work, I'm sorry.






          share|improve this answer













          How about this modification?



          Modified script:



          In this modified script supposes as follows.




          • Web Apps is deployed as



            • Execute the app as is Me


            • Who has access to the app is Only myself or Anyone



          • Your access token can be used for accessing to your Web Apps.
            If your access token cannot be used for it, please try to set the Web Apps as follows.
            - Execute the app as is Me
            - Who has access to the app is Anyone, even anonymous
            - In this setting, you can access to Web Apps without the access token.


          Python:



          import requests

          if __name__== "__main__":
          params = {
          'text': "is working?",
          }
          headers = {
          'Authorization': "Bearer [token]",
          }
          r = requests.post("https://script.google.com/macros/s/[uniquekey]/exec", data=params, headers=headers)
          print(r.status_code, r.reason)


          Note:


          • Please put the access token to the header.


          Google Apps Script:



          When you modified your script, please redeploy as new version. By this, the latest script is reflected to the Web Apps.



          function doPost(e) {
          const sheet = SpreadsheetApp.getActiveSheet();
          const range = sheet.getRange(1, 1);
          range.setValue(e.parameter.text);
          return ContentService.createTextOutput("Done.");
          }


          Note:


          • By returning ContentService.createTextOutput(), Web Apps returns the status code of 200.

          • You can retrieve the value of 'text': "is working?" as e.parameter.text.

          • When you use SpreadsheetApp.getActiveSheet(), the value of e.parameter.text is put to the 1st page of Spreadsheet.


          References:




          • Web Apps

          • ContentService


          In my environment, I could confirm that this modification worked. But if in your environment, this modified scripts didn't work, I'm sorry.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 '18 at 22:22









          TanaikeTanaike

          21.9k21123




          21.9k21123













          • thank you very much. changing the setting to "even anonymous" did work. I am still doing something wrong with the authorization token. I probably just dont fully know how to set that up through the google api auth system but this gets me on my way to setting up the sheet as I need to and I can work on the auth stuff later. thanks again.

            – Bastiat
            Nov 20 '18 at 15:12











          • @Bastiat Thank you for replying. I'm glad a part of your issue was resolved. About the authorization, for example, is this quickstart useful for you? developers.google.com/drive/api/v3/quickstart/python In this script, OAuth2 process is used.

            – Tanaike
            Nov 20 '18 at 22:16











          • were it just a project on my part, yea, I would just be using that. I had hoped to be able to do this just via standard requests without the library because I was just using python for testing while the actual use case would be push requests sent from a powershell environment. So I was trying to avoid those kinds of dependent libraries. Maybe that was a valid goal, maybe not.

            – Bastiat
            Nov 21 '18 at 14:52











          • @Bastiat Thank you for the additional information.

            – Tanaike
            Nov 21 '18 at 23:28



















          • thank you very much. changing the setting to "even anonymous" did work. I am still doing something wrong with the authorization token. I probably just dont fully know how to set that up through the google api auth system but this gets me on my way to setting up the sheet as I need to and I can work on the auth stuff later. thanks again.

            – Bastiat
            Nov 20 '18 at 15:12











          • @Bastiat Thank you for replying. I'm glad a part of your issue was resolved. About the authorization, for example, is this quickstart useful for you? developers.google.com/drive/api/v3/quickstart/python In this script, OAuth2 process is used.

            – Tanaike
            Nov 20 '18 at 22:16











          • were it just a project on my part, yea, I would just be using that. I had hoped to be able to do this just via standard requests without the library because I was just using python for testing while the actual use case would be push requests sent from a powershell environment. So I was trying to avoid those kinds of dependent libraries. Maybe that was a valid goal, maybe not.

            – Bastiat
            Nov 21 '18 at 14:52











          • @Bastiat Thank you for the additional information.

            – Tanaike
            Nov 21 '18 at 23:28

















          thank you very much. changing the setting to "even anonymous" did work. I am still doing something wrong with the authorization token. I probably just dont fully know how to set that up through the google api auth system but this gets me on my way to setting up the sheet as I need to and I can work on the auth stuff later. thanks again.

          – Bastiat
          Nov 20 '18 at 15:12





          thank you very much. changing the setting to "even anonymous" did work. I am still doing something wrong with the authorization token. I probably just dont fully know how to set that up through the google api auth system but this gets me on my way to setting up the sheet as I need to and I can work on the auth stuff later. thanks again.

          – Bastiat
          Nov 20 '18 at 15:12













          @Bastiat Thank you for replying. I'm glad a part of your issue was resolved. About the authorization, for example, is this quickstart useful for you? developers.google.com/drive/api/v3/quickstart/python In this script, OAuth2 process is used.

          – Tanaike
          Nov 20 '18 at 22:16





          @Bastiat Thank you for replying. I'm glad a part of your issue was resolved. About the authorization, for example, is this quickstart useful for you? developers.google.com/drive/api/v3/quickstart/python In this script, OAuth2 process is used.

          – Tanaike
          Nov 20 '18 at 22:16













          were it just a project on my part, yea, I would just be using that. I had hoped to be able to do this just via standard requests without the library because I was just using python for testing while the actual use case would be push requests sent from a powershell environment. So I was trying to avoid those kinds of dependent libraries. Maybe that was a valid goal, maybe not.

          – Bastiat
          Nov 21 '18 at 14:52





          were it just a project on my part, yea, I would just be using that. I had hoped to be able to do this just via standard requests without the library because I was just using python for testing while the actual use case would be push requests sent from a powershell environment. So I was trying to avoid those kinds of dependent libraries. Maybe that was a valid goal, maybe not.

          – Bastiat
          Nov 21 '18 at 14:52













          @Bastiat Thank you for the additional information.

          – Tanaike
          Nov 21 '18 at 23:28





          @Bastiat Thank you for the additional information.

          – Tanaike
          Nov 21 '18 at 23:28




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53382802%2fusing-an-http-request-to-update-google-spreadsheet%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Guess what letter conforming each word

          Port of Spain

          Run scheduled task as local user group (not BUILTIN)