小游戏开发getUserInfo:fail scope unauthorized

如题目小游戏开发遇到getUserInfo:fail scope unauthorized, 这个获取用户信息的接口之前调用正常,突然就不行了,找了很多原因结果发现是官方接口修改了,官方通知如下

https://developers.weixin.qq.com/blogdetail?action=get_post_info&lang=zh_CN&token=384460955&docid=000aee01f98fc0cbd4b6ce43b56c01


小游戏开发getUserInfo:fail scope unauthorized_第1张图片

其中小游戏相关

小游戏开发getUserInfo:fail scope unauthorized_第2张图片

https://developers.weixin.qq.com/minigame/dev/document/open-api/user-info/wx.createUserInfoButton.html

官方示例

var button = wx.createUserInfoButton({
    type: 'text',
    text: '获取用户信息',
    style: {
        left: 10,
        top: 76,
        width: 200,
        height: 40,
        lineHeight: 40,
        backgroundColor: '#ff0000',
        color: '#ffffff',
        textAlign: 'center',
        fontSize: 16,
        borderRadius: 4
    }
})
button.onTap((res) = > {
    console.log(res)
})

非最新版本的开发者工具会报错,需要升级到最新版,然后在在开发者工具右上角点击【详情】,项目设置里的调用基础库改成2.0.2版本,就可以使用wx.createUserInfoButton方法了, 开放数据域不能使用这个方法,要在主域用。

希望对近期遇到这个问题的开发者有所帮助

你可能感兴趣的:(小游戏)