Just a few months ago, Dialogflow, our favorite AI and Natural Language Processing platform for building chatbots, has released their V2 API . If you are thinking of migrating from V1 to V2 API, you should know that the V2 of the API relies on a Google Cloud Platform Service Account for authentication, instead of the previously used client and developer access tokens.
At the beginning of the migration, my team and I have spent researching on how to use the Google Cloud Platform Service Account for authentication. Therefore, the purpose of this blog post is to help you guys save some time and get started with the V2 DialogFlow API easily.
Go to your agent's setting. Ensure that your API version is set to V2 and click on your service account link (we have masked ours for security reason).
This will open your Google Cloud Platform project's service account page. Under 'Dialogflow integrations' service account name, click on the 3 vertical dots at the far right and choose 'Create key'. A JSON file will be downloaded to your computer.
Now that you have setup your service account, it is time to move on to the coding part. The library that is used in the code below is google-oauth-jwt.
That's it, you have generated your own access token.