ESP32 GOOGLE SCRIPT

nodoubtman
Posts: 2
Joined: Wed Apr 16, 2025 11:12 pm

ESP32 GOOGLE SCRIPT

Postby nodoubtman » Wed Apr 16, 2025 11:15 pm

Hello, i have created a google script fetching my calendar, i use ESP32 to access it, here's my code:

Code: Select all

String Get_Location() {
  HTTPClient http;

  WiFiClientSecure calendarClientSecure;
  //calendarClientSecure.setCACert(GOOGLE_CERT);
  calendarClientSecure.setInsecure();

  const char * headerKeys[]    = {"Location"};
  const size_t numberOfHeaders = sizeof(headerKeys) / sizeof(char*);

  bool calendarBeginsOK = http.begin(calendarClientSecure,
                                     F("script.google.com"),
                                     443,
                                     F("/macros/s/AKfycbwuHDmdhWbvgqK4cPUyFRCaznaifilgxLwT9J93Hb4xAYbCaPCMoze3GMUQKF1lGka4/exec"),
                                     true);

  Serial.printf("calendarBeginsOK: %d\n", calendarBeginsOK);

  if (calendarBeginsOK == false) {
    http.end();
    return F("");
  }

  http.collectHeaders(headerKeys, numberOfHeaders);

  http.setTimeout(15000);

  int httpCode = http.GET();
  Serial.printf("httpCode: %d\n", httpCode);
  if (httpCode == HTTP_CODE_FOUND) {  // 302
    Serial.println( F("Found!") );

    String httpHeader = http.header(0U).c_str();
    Serial.printf("httpHeader\n%s\n", httpHeader.c_str());

    /*
        int indexFollowUpOK = httpHeader.indexOf("followup=") + 9;
        Serial.printf("indexFollowUp: %d\n", indexFollowUpOK);

        String realPath = httpHeader.substring(indexFollowUpOK);
        Serial.printf("realPath\n%s\n", realPath.c_str());
    */

    String realPathOK = urldecode(httpHeader);
    Serial.printf("realPathOK\n%s\n", realPathOK.c_str());

    http.end();
    return realPathOK;
  }  // if (httpCode == HTTP_CODE_FOUND)
  else
  {
    http.end();
    return F("");
  }

  if (http.connected())
    http.end();

  return F("");
}
I get this response:
https://accounts.google.com/ServiceLogi ... lGka4/exec

what does it means?
i cannot request the same url.

Can you help me?
Thanks.
Marc.

Sprite
Espressif staff
Espressif staff
Posts: 10609
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32 GOOGLE SCRIPT

Postby Sprite » Thu Apr 17, 2025 2:52 am

I'd guess that Google wants you to log in before allowing access to the calendar. Open the link in a private browser and you'll probably see the login screen.

nodoubtman
Posts: 2
Joined: Wed Apr 16, 2025 11:12 pm

Re: ESP32 GOOGLE SCRIPT

Postby nodoubtman » Thu Apr 17, 2025 10:55 am

Hi. Thanks for the reply.
I open the link in the browser, and it shos the calendar datas, not in the ESP32.
Is there any way to fix this ?

Thanks.
Marc.

Sprite
Espressif staff
Espressif staff
Posts: 10609
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32 GOOGLE SCRIPT

Postby Sprite » Fri Apr 18, 2025 2:50 am

Yes, because you are logged into Google on that browser. That's why I told you to try it in a *private* browser session (aka incognito mode in Chrome). I'm decently sure that is the issue, because I loaded the URL here and I indeed get a login screen of sorts.

Who is online

Users browsing this forum: PetalBot, trendictionbot and 4 guests