1

Hi I'm trying to get the calendar events through esp32 and I'm using NodeMCU firmware with Lua(5.1) (Nodemcu: https://nodemcu.readthedocs.io/en/dev-esp32/modules/http/) everything I've done correctly I wrote google script for the same and tested with chrome and postman in both cases url worked fine but when tried with esp32 it's not... I can't able to debug myself, help me debugging the issue.

here is the code I've been trying

headers = {["Content-Type"] = "application/json", ["Host"]="script.google.com",["Accept"]= "application/json, text/plain, /" ,}
connection = http.createConnection("https://script.google.com/macros/s/AKfycbybO_1kyXTxTOAJ8d4X0niOs-7y58TIfBhD92ThMuh8GJ/exec", http.GET, { headers=headers } )
connection:on("data", function(status,data)
  print("data =", status,data)
end)
connection:request()

and the error I'm getting is

<HEAD>
<TITLE>Moved Temporarily</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Moved Temporarily</H1>
The document has moved <A HREF="https://script.googleusercontent.com/macros/echo?user_content_key=S3EjAkUDuxNdm-9dm2FVF3DWmazC_Qh0BGbIh1FAM_v_VkANvqPIszl-v-NCgqVk-jzU4NDO6FSjYkUTckVub_o2vxQNHFTUm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_1xSncGQajx

data =  404 <!DOCTYPE html><html lang="en"><head><meta name="description" content="Web word processing, spreadsheets and presentations"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0"><link rel="shortcut icon" href="//docs.google.com/favicon.ico"><title>Page not found</title><meta name="referrer" content="origin"><link href="//fonts.googleapis.com

data =  404 /css?family=Product+Sans" rel="stylesheet" type="text/css" nonce="BbT+xY6IwnjihR7Y0w7wAw"><style nonce="BbT+xY6IwnjihR7Y0w7wAw">/* Copyright 2021 Google Inc. All Rights Reserved. */
.goog-inline-block{position:relative;display:-moz-inline-box;display:inline-block}* html .goog-inline-block{display:inline}*:first-child+html .goog-inline-block{display:inline}#drive-logo{margin:

data =  404 18px 0;position:absolute;white-space:nowrap}.docs-drivelogo-img{background-image:url('//ssl.gstatic.com/images/branding/googlelogo/1x/googlelogo_color_116x41dp.png');background-size:116px 41px;display:inline-block;height:41px;vertical-align:bottom;width:116px}.docs-drivelogo-text{color:#000;display:inline-block;opacity:0.54;text-decoration:none;font-family:'Product Sans',Arial,Helvetica,sans-serif;font-size:32px;text-rendering:optimizeLegibility;position:relative;top:-6px;left:-7px;-webkit-font-smoothing:an

data =  404 tialiased;-moz-osx-font-smoothing:grayscale}@media (-webkit-min-device-pixel-ratio:1.5),(min-resolution:144dpi){.docs-drivelogo-img{background-image:url('//ssl.gstatic.com/images/branding/googlelogo/2x/googlelogo_color_116x41dp.png')}}</style><style type="text/css" nonce="BbT+xY6IwnjihR7Y0w7wAw">body {background-color: #fff; font-family: Arial,sans-serif; font-size: 13px; margin: 0; padding: 0;}a, a:link, a:visited {color: #112ABB;}</style><style type="text/css" nonce="BbT+xY6IwnjihR7Y0w7wAw">.errorMessage 

data =  404 {font-size: 12pt; font-weight: bold; line-height: 150%;}</style></head><body><div id="outerContainer"><div id="innerContainer"><div style="position: absolute; top: -80px;"><div id="drive-logo"><a href="/"><span class="docs-drivelogo-img" title="Google logo"></span><span class="docs-drivelogo-text">&nbsp;Drive</span></a></div></div><div align="center"><p class="errorMessage" 

data =  404 style="padding-top: 50px">Sorry, unable to open the file at present.</p><p> Please check the address and try again.</p><div style="background: #F0F6FF; border: 1px solid black; margin-top: 35px; padding: 10px 125px; width: 300px;"><p><strong>Get stuff done with Google Drive</strong></p><p>Apps in Google Drive make it easy to create, store and share online documents, spreadsheets, presentations and more.</p><p>Learn more at <a href="https://drive.google.com/start/apps">drive.google.com/start/apps</a>.</p></d

data =  404 iv></div></div></div></body><style nonce="BbT+xY6IwnjihR7Y0w7wAw">html {height: 100%; overflow: auto;}body {height: 100%; overflow: auto;}#outerContainer {margin: auto; max-width: 750px;}#innerContainer {margin-bottom: 20px; margin-left: 40px; margin-right: 40px; margin-top: 80px; position: relative;}</style></html>

I tried different headers but no use use and I tried implementing uploading the data to google spread sheet. Same issue url worked with browser, Postman and with esp32, it's uploading data to spreadsheet but error is same(404). I can't understand why....

Abhi
  • 73
  • 8
  • What do you imagine “moved temporarily” might mean? Or “The document has moved”? – romkey Nov 26 '21 at 05:59
  • Hi @romkey I've no idea about that.. – Abhi Nov 26 '21 at 07:01
  • How might you find out? Starts with a “g”, ends with an “e”. – romkey Nov 26 '21 at 07:10
  • Also you really should check the status variable. – romkey Nov 26 '21 at 07:11
  • Sorry @romkey I'm beginner, didn't understand what are you talking about and I need the events returned by the calendar (from the google script url) – Abhi Nov 26 '21 at 07:34
  • I see in your code that you are pointing to a script link to make the request. If you want to work with calendar you should be checking the [API Reference](https://developers.google.com/calendar/api/v3/reference), the main endpoint is `https://www.googleapis.com/calendar/v3`. If you need to run a script, you should be using the Google Apps Script [REST API](https://developers.google.com/apps-script/api/reference/rest/v1/scripts/run), note that the URL ends in `:run`. – Emel Nov 26 '21 at 08:30
  • Hi @Emel, I deployed script as web app not as API – Abhi Nov 26 '21 at 08:44
  • If you want to run a function, you should make a deploy as API Exec. You can check [this](https://developers.google.com/apps-script/api/how-tos/execute) guide to know how to do it. – Emel Nov 26 '21 at 08:47
  • @Emel please excuse my stupidity, I want to know why I can able to get the calendar events through Postman and browser not with ESP32, just want to make sure where I'm doing wrong, because I got this idea from one of youtube videos only. They just deployed as a web app and it worked. I hope you understand my pain.... – Abhi Nov 26 '21 at 09:32
  • To better understand what the problem is, could you explain how you make this request through PostMan? It seems that it doesn't detect that you are authenticated and maybe you need to add an [OAuth Token](https://developers.google.com/identity/protocols/oauth2) to your request. – Emel Nov 26 '21 at 09:47
  • Hi @Emel I'm just doing get request through Postman, I understand my problem little bit that is my esp32 can able to send request properly but in response googlescript giving in html that response cannot be properly handled by esp32 that is the issue as per my knowledge – Abhi Nov 27 '21 at 06:38
  • Since you are getting a [404](https://en.wikipedia.org/wiki/HTTP_404), it doesn't seem to be detecting that you are making the request from an authenticated point or that you are not setting the URL correctly. Have you tried adding `["Authentication"] = "Bearer YOUR_TOKEN"` to the request? – Emel Nov 30 '21 at 10:21

1 Answers1

0

Hi I discovered the solution, first the problem is with ESP32 http request, http buffer size is less so that's why after redirecting, the authentication token is not receiving fully (default is 512 bytes insufficient) so it can't able to make that request(can't able to redirect token to google) giving 404 error. After increasing the buffer it worked. In the below code updated buffer size to 2048

connection=http.createConnection("https://script.google.com/macros/s/AKfycbyg3q6yhMQGWmPPH2e95/exec",  http.GET,{bufsz=2048} )
connection:on("data", function(status,data)
  print("data returned =", status,data)
end)
connection:on("complete", function(status)
  print("Request completed with status code =", status)
end)
connection:request()

If anybody wants I can share detailed info...

Abhi
  • 73
  • 8