6

I'm trying to use DialogFlow REST API with api key auth method. For example

https://dialogflow.googleapis.com/v2/projects/projectId/agent?key=[YOUR_API_KEY]

but It desn't work. This is the result

{ "error": { "code": 401, "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", "status": "UNAUTHENTICATED" } }

Lorenzo Vannucchi
  • 359
  • 1
  • 3
  • 11
  • 1
    https://chatbotslife.com/dialogflow-v2-rest-api-communication-6cf7ab66ab36 – Nikhil Savaliya Jan 02 '20 at 15:56
  • Did you solve your problem? I have the same issue – FCLM Jan 11 '22 at 16:55
  • I solved using Account Service JSON generated inside GCP IAM with involved roles like admin api dialogflow role. Then, I generate Authorization Bearer token with GoogleCredentials api and then I pass auth token to header of request. Hope this helps – Lorenzo Vannucchi Jan 19 '22 at 23:22

1 Answers1

0

Please find solution using technology Asp.Net Core Web API :-

Step 1 : Install Nuget Package mention name "Google.Apis" and "Google.Apis.Dialogflow.v2"

Step 2: Generate a credential in json file using Service Accounts

Step 3: User this code to generate a token using Google Service Accounts. find below code

  var fileName = path + "Keys\\client_secret_file.json";

                var combinePath = Path.Combine(fileName);

                var credentials = GoogleCredential.FromFile(combinePath);
                var scopedCredentials = credentials.CreateScoped(DialogflowService.Scope.Dialogflow);
               var _oAuthToken = scopedCredentials.UnderlyingCredential.GetAccessTokenForRequestAsync().Result;