DialogFlow v2 Access Token cannot generate

前端 未结 3 728
借酒劲吻你
借酒劲吻你 2021-01-14 01:42

With version 1 this is how I used to communicate with DialogFlow Api!

fetch(configs.baseUrl + \"query?v=20150910\", {
    body: JSON.stringify({query: text,          


        
相关标签:
3条回答
  • 2021-01-14 02:16

    Below is another example of creating your DialogFlow V2 access token using Node.js. The library that is used in the code below is google-oauth-jwt.

    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);
       },
      );
     });
    }
    

    You may find your client_email and private_key from 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.

    0 讨论(0)
  • 2021-01-14 02:21

    You might be interested in this:

    https://cloud.google.com/docs/authentication/api-keys

    0 讨论(0)
  • 2021-01-14 02:36

    You did pretty much the right thing, but you would probably want to use Dialogflows Node.js client SDK. These SDKs read the authentication JSON file automatically when you instantiate a client (see the example on Github, the file is read by ... = new dialogflow.SessionsClient()).

    0 讨论(0)
提交回复
热议问题