我在python中使用dialogflow。我这样调用API V2:
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "project/xx-prototype-v2-xxxxx.json"
import dialogflow_v2 as dialogflow
session_client = dialogflow.SessionsClient()
session = session_client.session_path(project_id, session_id)
现在,我需要使用来自同一python模块的多个.json凭证文件访问多个代理。
是否有一种聪明的方法来为具有各自凭据json文件的多个dialogflow代理设置此代码?
答案 0 :(得分:3)
您可以在实例化SessionClient
时传递身份验证信息,如以下示例代码所示:
const client = new dialogflow.SessionsClient({
credentials: {
client_email: "svc-acc@project-id.iam.gserviceaccount.com",
private_key: "---BEGIN.....END-----"
},
projectId: "your-project-id"
})
对于不同的代理/项目,您可以传递不同的身份验证信息。例如
const client1 = new dialogflow.SessionsClient({
credentials: {
client_email: "service-account-email-1@project-id.iam.gserviceaccount.com",
private_key: "---BEGIN.....END-----" //service account private key 1
},
projectId: "your-project-id-1"
})
// use client1 and make any needed API calls to your first agent
const client2 = new dialogflow.SessionsClient({
credentials: {
client_email: "service-account-email-2@project-id.iam.gserviceaccount.com",
private_key: "---BEGIN.....END-----" //service account private key 2
},
projectId: "your-project-id-2"
})
// use client2 and make any needed API calls to your second agent
// instantiate more clients as needed...