Setting up OAuth 2.0 for Dialogflow API Integration

Hi,

I have a question regarding the integration of Dialogflow API with TARS which was demoed here and which is great by the way.

What is the correct way of setting OAuth 2.0 on Dialogflow API’s side and obtaining the authorization code, access token, and refresh tokens?

I’ve tried to follow the instructions from Google’s documentation on setting OAuth here but couldn’t get passed the access and refresh token stage. I.e. After obtaining the authorization code (and client ID and client secret) from Google, when I request for the access and refresh token using the following HTTP request snippet (recommended by Google) from TARS’s API config window of a gambit:

POST /token HTTP/1.1
Host: oauth2.googleapis.com
Content-Type: application/x-www-form-urlencoded

code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp7&
client_id=your_client_id&
client_secret=your_client_secret&
redirect_uri=https%3A//oauth2.example.com/code&
grant_type=authorization_code

I’m getting the 400 error shown below:

{
  "error": "invalid_grant",
  "error_description": "Bad Request"
}

Can someone please help me understand what I’m doing wrong or perhaps show me the corret way?

Thank you,
Nat