someone have build a python project with the new dialogflow library from python language, I already make it work with implicit credentials but now I need to make it work with explicit credentials.
This is the error:
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials.
Please set GOOGLE_APPLICATION_CREDENTIALS or
explicitly create credential and re-run the application. For more
information, please see
https://developers.google.com/accounts/docs/application-default-credentials.
The url only explain explicit credentials.
This is the code that am using:
import dialogflow
def create_intent(project_id, display_name, training_phrases_parts,
message_texts):
"""Create an intent of the given intent type."""
intents_client = dialogflow.IntentsClient()
parent = intents_client.project_agent_path(project_id)
training_phrases = []
for training_phrases_part in training_phrases_parts:
part = dialogflow.types.Intent.TrainingPhrase.Part(
text=training_phrases_part)
# Here we create a new training phrase for each provided part.
training_phrase = dialogflow.types.Intent.TrainingPhrase(parts=[part])
training_phrases.append(training_phrase)
text = dialogflow.types.Intent.Message.Text(text=message_texts)
message = dialogflow.types.Intent.Message(text=text)
intent = dialogflow.types.Intent(
display_name=display_name,
training_phrases=training_phrases,
messages=[message])
response = intents_client.create_intent(parent, intent)
print('Intent created: {}'.format(response))
At the end was the same that google.cloud library from python
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="./path_to.json"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.