我已成功地通过action-on-google nodejs库请求用户位置,但我更多的是java小伙子,我需要在java中执行此操作。在没有nodejs库的情况下请求用户位置
https://developers.google.com/actions/assistant/helpers#json
How can I request the user's location in API.ai?
Requesting User Location from Google Actions with Api.ai
从上面的链接,我发现这是可能的只是JSON反应变量。
我创建了一个api.ai我POC的应用程序,它返回以下JSON反应变量
{
"conversationToken": {
"state": null,
"data": {}
},
"expectUserResponse": true,
"expectedInputs": [
{
"inputPrompt": {
"initialPrompts": [
{
"textToSpeech": "PLACEHOLDER_FOR_PERMISSION"
}
],
"noInputPrompts": null
},
"possibleIntents": [
{
"intent": "actions.intent.PERMISSION",
"inputValueData": {
"@type": "type.googleapis.com/google.actions.v2.PermissionValueSpec",
"optContext": "Requesting Location.",
"permissions": [
"DEVICE_COARSE_LOCATION"
]
}
}
]
}
]
}
这将返回: Unparseable Json Response
{
"contextOut": [
{
"lifespan": 100,
"name": "_actions_on_google_",
"parameters": null
},
{
"lifespan": 5,
"name": "requesting_permission",
"parameters": null
}
],
"data": {
"google": {
"expect_user_response": true,
"is_ssml": false,
"no_input_prompts": null,
"permissions_request": {
"opt_context": "Requesting Location.",
"permissions": [
"DEVICE_COARSE_LOCATION"
]
}
}
},
"speech": "PLACEHOLDER_FOR_PERMISSION"
}
此退货: PLACEHOLDER TEXT
我想知道我这样做的方式是否可行。如果是,我做错了什么?
请帮忙。
现在有一个非官方的Java /科特林SDK。它具有nodejs和非常类似的API的所有功能。我维护这个项目,并且很快就会更新文档和自述文件,但它已经可以使用并且处于Maven核心。 https://github.com/TicketmasterMobileStudio/actions-on-google-kotlin – Patrick
@Patrick谢谢,我会看看 – Sukh