OH3 Google TTS: [ERROR] [oauth2client.internal.OAuthConnector] - grant type authorization_code

Hi,
I’m migrating from OH2 to OH3. In OH2 I had Google TTS working for years.
Now I can’t get it to work. I’ve followed the instructions in Google Cloud Text-to-Speech - Voices | openHAB to obtain the web app credentials (I had the credentials for OH2, which were for desktop type). The project is named “openHAB”.
But when I try to get the authorization code, the Google account selection page prompts me to select a Google account (I have several) to access a project named “Quickstart”, not “openHAB”. Quickstart is another GCP I have.
If I continue and get the authorization code, I get the following error starting OH3 (which I find normal, since the authorization code is for a different project):

2022-12-16 22:54:11.117 [ERROR] [oauth2client.internal.OAuthConnector] - grant type authorization_code to URL https://accounts.google.com/o/oauth2/token failed with error code invalid_grant, description Bad Request
2022-12-16 22:54:11.124 [WARN ] [ce.googletts.internal.GoogleCloudAPI] - Error initializing Google Cloud TTS service: Error fetching access token. Invalid authcode? Please generate a new one.

How can I specify the project in the URL to request the authorization code?
Thank you.

There is a long discussion about that topic here : OH3 Google TTS: Error - grant type authorization_code - #45 by stefan.hoehn

Can you check my recommended steps there? May that helps.

Hi,
I had already read that thread and followed your instructions:

  • I added the Google TTS in services/addons.cfg (I already had it in OH2):
voice = googletts

In Setting/Addons it appears as installed.

  • I had alread read and followed the pages Multimedia | openHAB and Google Cloud Text-to-Speech - Voices | openHAB

  • I already had a project created with the TTS API enabled in Google Cloud, because I had it working in OH2. This project is called “openHAB”.

  • I already had credentials for this project for OH2, but they were desktop type (“OAuth client”). Yesterday, following the instructions for OH3 I created the web app credentials (“TTS openHAB”):


    I don’t have an API key, though. It wasn’t in the instructions and I don’t know where to use it. Do I have to create it?

  • I wrote down the client ID and secret.

  • In the consent screen I made sure the status is Production (it already was).

  • My OH is all configured in files. In services/googletts.cfg I have:

org.openhab.voice.googletts:clientId=MY_CLIENT_ID
org.openhab.voice.googletts:clientSecret=MY_SECRET
org.openhab.voice.googletts:authcode=MY_AUTH_CODE
org.openhab.voice.googletts:pitch=0
org.openhab.voice.googletts:volumeGain=0
org.openhab.voice.googletts:speakingRate=1
org.openhab.voice.googletts:purgeCache=false

And it appears to be ok if I go to the GUI.
I believe the problem is when I get the authorization code I see this:

When I select the account I get a page saying that Google hasn’t verified this application, but in advanced configuration I can continue:

Do I have to do anything to verify the application?

Then I get a page where I grant permissions:


I continue and I get the authorization code from de parameter in the URL. It is what I copy in org.openhab.voice.googletts:authcode=MY_AUTH_CODE in services/googletts.cfg and appears in the web GUI.
But then I restart openHAB and I get the error and the waring in the log.
I believe I have a problem retrieving the authorization code because the name of the project that appears in the account selection and the permission granting pages is “Quickstart”, but it should be “openHAB”. Is this correct? Am I doing something wrong?
Thank you very much.

I’ve repeated the process for the project “Quickstart” and it works. Is there a way to do it for the project “openHAB”?

It worked (I’m not sure now, but I even got an alert email), but I have restarted OH and I’m getting the same error. I’m lost.

All I can say is that I thoroughly documented the steps and I lately recreated everything from scratch (and it worked well) to make sure the steps I documented work out correctly. I would recommend to start from scratch exactly how I wrote it. Otherwise we would have to check were you diverted from that (at least you edited files on the server which I haven’t documented in my steps).

This is the verification step:

“Fill in clientId in to the following URL and retrieve authorisation code”

https://accounts.google.com/o/oauth2/v2/auth?scope=https://www.googleapis.com/auth/cloud-platform&access_type=offline&prompt=consent&include_granted_scopes=true&response_type=code&redirect_uri=https://www.google.com&client_id=MYCLIENTID

It will return the code that you then enter in the GUI.

You don’t have to change files on the server. Please do as I described. You also don’t have to restart openHAB.

Hi,
With the configuration in files I got it to accept the authentication code but I had no voices listed in the karaf console.
I started from scratch from the GUI and now it’s all working. I’m going to leave it like this, I’m tired of fiddling with this.
Thank you very much for your help!!!

1 Like

Recently upgraded OH from 3.3 to 3.4.2. but still after OH restart Google TTS stop working …Maybe someone know when issue with authcode wil be fixed? When I generate new authcode it is working till restart…

@Roberto2 did you solve this?
I have the same problem.

Is this with config from text files or via UI?
While I prefer config by text files myself I found that refreshing the auth token seems to fail with config files. Google TTS is about the only thing I config via the UI for that reason.

That said, I still have to create a new auth code once or twice a week, oauth2.0 with Google is a fragile affair and all the irritating dialogs and warnngs on top of it - not for the faint of heart.

Hi @rubens ,
My Openhab config is 100% pure textual. This way a have easy way to have config versioning etc. I don’t see any benefits with UI config,my main ui is sitemap file :slight_smile:
If there will be no fix for Google TTS then I am planning switch back to OH 2.5

Apparently Google changed the oauth2 structeres again. When creating credentials, one can not select an application type. Also “Authorized redirect URIs” does not accept “https://www.google.com” anymore. I can not find a solution.

Many thanks for all these tutorials and guidelines. I followed all of them.
But I struggle since several time to get it to work. I already tried it with “Web Application”, then I get a token.
But it won’t work. Now, I want to try it with “Desktop Application”
But here I get the following error from Google:
tts_error
Wrong request…
But there is no Redirect URI in Desktop mode.

Is propably another TTS Service easier to handle?
Many thanks