I am using ESP8266 programmed from Arduino to get data from the Google Youtube API. API, of course, works great in a browser using URL:


The problem is that "gooogleapis.com" is not the location where from I would receive the answer to my HTTPS request, it comes from a different location. When above URL is entered, it is being redirected and request answer comes from another location.

So what happens on ESP8266 when I try to open that address(of course, with added proper channel ID and google key) is following:

HTTP/1.1 404 Not Found
Content-Type: text/html; charset=UTF-8
Content-Length: 1580
Date: Sun, 12 Mar 2017 14:40:18 GMT
Alt-Svc: quic=":443"; ma=2592000; v="36,35,34"
Connection: close

<!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 404 (Not Found)!!1</title>
    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
  <a href=//www.google.com/><span id=logo aria-label=Google></span></a>
  <p><b>404.</b> <ins>That’s an error.</ins>
  <p>The requested URL <code>/youtube/v3/channels</code> was not found on this server.  <ins>That���s all we know.</ins>

Which is the Google error page(you seen it!). This is my Arduino code:

#include "ESP8266WiFi.h"
#include <WiFiClientSecure.h>

const char* ssid     = "SSID";  // WiFi network name
const char* password = "pass"; // WiFi pass

const char* host = "googleapis.com"; // page I am trying to load
const char* fingerprint = "22 37 4D 58 43 F4 A1 24 12 71 2B 74 7A FC 36 FC 24 A0 F0 9D";

String ch_id = "CHANNEL ID";
String api_key = "API KEY";

void setup() {

  WiFi.begin(ssid, password); 

  while (WiFi.status() != WL_CONNECTED) { 

  Serial.println("Connected to WiFi! Local IP address is: ");

  WiFiClientSecure client; 
  if (!client.connect(host, 443))
    Serial.println("I am unable to connect to that page."); 

  if (client.verify(fingerprint, host)) {
    Serial.println("certificate OK");
  } else {
    Serial.println("certificate NOT OK");

  String url = "/youtube/v3/channels?part=statistics&id=" + ch_id + "&key=" + api_key;

  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Connection: close\r\n\r\n");

  while (client.available()) {
    String linija = client.readStringUntil('\r'); 


void loop() { 
  • How to find out to which site I am redirected?
  • How to read that from ESP8266 and redirect the same data to new site?
  • 1
    404 is not a redirect. You should get a 302 or 301. In that case there will also be a Location: header that contains the new URL. – Gerben Mar 12 '17 at 15:53

In your browser you used www.googleapis.com, but in your code you used googleapis.com.


returns a 404 page.

Add www. to your host in code.

  • Perfect! Can't believe I missed something so trivial. Thank you very much - works now. – davaradijator Mar 13 '17 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.