Google Action请求PHONE_NUMBER权限失效,按文档实现仍报错求排查
Let's break down the possible issues with your permission request response and fix them step by step:
1. Replace the Placeholder Text in textToSpeech
The biggest red flag here is the PLACEHOLDER_FOR_PERMISSION value in your textToSpeech field. The simulator can't parse this generic placeholder—you need to replace it with a natural, user-facing prompt that clearly explains why you're asking for their phone number. For example:
"textToSpeech": "Could I get your phone number to arrange delivery of your order?"
2. Confirm Permission String & API Version Compatibility
Your response uses the v2 API type (type.googleapis.com/google.actions.v2.PermissionValueSpec). If you're building with a newer SDK (like Actions Builder or the v3 client library), using a v2 response structure will cause compatibility errors.
- If you intend to use v3, update the
@typeto:"@type": "type.googleapis.com/google.actions.v3.PermissionValueSpec" - For both v2 and v3, the permission identifier
"PHONE_NUMBER"is correct—but double-check for typos (capitalization matters here).
3. Enable the Phone Number Permission in the Actions Console
Even if your code is perfect, you need to explicitly enable the phone number permission in your project settings:
- Open the Actions Console and select your project
- Navigate to Develop > Account Linking > Permissions
- Add the "Phone Number" permission and save your changes
4. Validate Your JSON Syntax
A tiny syntax error (like a missing comma or mismatched bracket) can cause the simulator to throw an "unexpected error". Run your response through a JSON validator to catch any hidden typos.
Here's a corrected v2-compatible version of your response with proper prompt text:
{ "conversationToken": "TOKEN", "expectUserResponse": true, "expectedInputs": [ { "inputPrompt": { "initialPrompts": [ { "textToSpeech": "Could I get your phone number to deliver your order?" } ], "noInputPrompts": [] }, "possibleIntents": [ { "intent": "actions.intent.PERMISSION", "inputValueData": { "@type": "type.googleapis.com/google.actions.v2.PermissionValueSpec", "optContext": "To deliver your order", "permissions": [ "PHONE_NUMBER" ] } } ] } ] }
Try implementing these fixes one by one—chances are the placeholder text or missing console permission setup is the root cause.
内容的提问来源于stack exchange,提问作者oschwarzpdm

