Last active
July 20, 2022 11:06
-
-
Save weikangchia/d5bb0aa1466407c86692ba00d8f16332 to your computer and use it in GitHub Desktop.
Generate DialogFlow V2 Access Token
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const googleAuth = require('google-oauth-jwt'); | |
| function generateAccessToken() { | |
| return new Promise((resolve) => { | |
| googleAuth.authenticate( | |
| { | |
| email: <client_email>, | |
| key: <private_key>, | |
| scopes: 'https://www.googleapis.com/auth/cloud-platform', | |
| }, | |
| (err, token) => { | |
| resolve(token); | |
| }, | |
| ); | |
| }); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want to generate the DialogFlow V2 access token through the "vanilla" way, you have come to the right place. In the above code, we will be using a nodejs package called, google-oauth-jwt, to help us generate the DialogFlow V2 access token.
You may find your
client_emailandprivate_keyfrom the JSON key file you have downloaded from your Google Cloud Platform project's service account page. If you are unsure how/where to download it, you may checkout my blog post here.To find out which scope which scope you may need, you may checkout the DialogFlow V2 REST API documentation page.