httpClient() to GoogleSheets

I've been tasked to try to connect some spreadsheets to Ignition to read data and update some information in our dashboards.

I started to look into the Google Sheets API and the Oauth2 I can't get past the authentication, it no matter what I have tried it always says access is blocked.

Then I tried with httpClient() and client.post() with the clientID and clientSecret I had generated in the Google auth Platform but I get the same response when I print client.text.

<HTML>
<HEAD>
<TITLE>Moved Temporarily</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<!-- GSE Default Error -->
<H1>Moved Temporarily</H1>
The document has moved <A HREF="https://accounts.google.com/signin/oauth/error?authError= ... >here</A></BODY>
</HTML>

If I can get some direction it would be appreciated.

If the webserver is responding with an HTML body you likely need to pass explicit content type and/or accept headers in your requests.

A "moved permanently" might also be because httpClient by default doesn't follow redirects; you can change that when constructing your httpClient instance:

I was declaring the headers according to another post I saw. But solution was the redirection, just had to change the parameter to redirectPolicy = "NORMAL" and I got response with the data. I also tried to do kwargs but it wouldn't work so I had to declare the other parameters to their default value.

For posterity here was the code I was testing:

headerValues = {
    'client_id':'clientid.apps.googleusercontent.com',
    'client_secret': client_secret,
    'grant_type' : 'client_credentials',
    }
authServerURL = 'https://accounts.google.com/o/oauth2/auth'
redirectPolicy = "NORMAL"
timeout = 10000
bypassCertValidation = False
username = None
password = None
proxy = None
cookiePolicy = "ACCEPT_ORIGINAL_SERVER"


#Send POST
client = system.net.httpClient(timeout, bypassCertValidation, username, password, proxy, cookiePolicy, redirectPolicy)
response = client.post(authServerURL, "https://docs.google.com/spreadsheets/d/fileURL", headerValues)
print response.statusCode
print response.text