小程序

小程序收货地址报错chooseAddress:fail the api need to be declared in the requiredPrivateInfos field inapp.json

2022-12-09

最近做的小程序商城项目获取微信小程序收货地址接口wx.chooseAddress时,返回errMsg为: "chooseAddress:fail the api need to be declared in the requiredPrivateInfos field in app.json/ext.json"

小程序选择地址接口错误.jpg

原因分析:

这是由于微信官方做了优化,自 2022 年 7 月 14 日后发布的小程序,若使用该接口,需要在 app.json 中进行声明,否则将无法正常使用该接口,2022年7月14日前发布的小程序不受影响。


解决方案:

一、uni-app项目

打开小程序项目配置文件,src/manifest.json文件,注意插入代码位置。代码中还有其它配置项,可以多试一下,我的仅添加一个便解决了,注意配置完保存后要重新运行一下项目。

小程序选择地址接口错误解决方法.jpg

 "mp-weixin": { /* 微信小程序特有相关 */

        "appid": "",

        "setting": {

            "urlCheck": false

        },

        "usingComponents": true,

        "requiredPrivateInfos": [

             //"getFuzzyLocation",

             //"choosePoi",

            "chooseAddress"

        ]

    },

二、原生小程序

1、需配置的接口列表:




2、配置规则

在 app.json 中 requiredPrivateInfos 配置项中声明,代码如下:

"requiredPrivateInfos":[

    "getFuzzyLocation",

    "choosePoi",

    "chooseAddress"

]