在小程序工具清理掉所有缓存后再次发起用户授权请求仍然会发生系统错误问题?

小程序 文章 2020-09-03 15:41 0 77 全屏看文

在小程序工具清理掉所有缓存后再次发起用户授权请求仍然会发生系统错误问题?After the mini program tool clears all the caches, the system error will still occur if the user authorization request is initiated again?

在小程序工具清理掉所有缓存后再次发起用户授权请求仍然会发生系统错误问题?
        /* 获取用户信息 */        wx.getSetting({            success(res) => {                // 如果用户已经授权 scope.userInfo 这个 scope                if (res.authSetting['scope.userInfo']) {                    // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框                    console.log("用户已授权")                    wx.getUserInfo({                        success(res) => {                            console.log("用户信息", res)                            }                        }                    })                } else { // 向用户发起授权请求                    console.log('向用户发起授权请求 scope.userInfo')                    wx.authorize({                        scope'scope.userInfo',                        success(suc) {                            console.log("用户已授权", suc                        },                        fail(err) {                            console.log("无法授权", err)                        },                        complete(c) {                            console.log("授权函数执行", c)                        }                    })                }            }        })

提示如下错误信息

errMsg: "authorize:fail 系统错误,错误码:-12007,scope unauthorized"

截图

此时,只能通过用户主动去点击授权按键才会调出授权页面,但是就做不到首次打开小程序主动调出授权页面的要求了

/ * get user information * / wx.getSetting ({success: (RES) = > {/ / if the user is authorized scope.userInfo This scope if( res.authSetting ] scope.userInfo '] {/ / authorized, OK Call getUserInfo directly to get the nickname of the avatar without pop-up console.log (user authorized) wx.getUserInfo ({                        success: (res) => {                             console.log (user information), Res)}}}}} else {/ / issue authorization request to user console.log ('initiate authorization request to user scope.userInfo ')                      wx.authorize ({                        scope: ' scope.userInfo ',                        success(suc) {                             console.log (user authorized, suc},                         fail(err) {                             console.log (unable to authorize, ERR)},                         complete(c) {                             console.log (authorization function execution), (c)}}}}}}) the following error message is displayed“ authorize:fail System error, error code: - 12007, "Scope unauthorized" screenshot: at this time, the authorization page can only be called up by clicking the authorization button actively by the user. However, it is not possible to open the applet to call up the authorization page for the first time

回答:

citizen four:

谢邀,必须用户主动触发授权,不能强制,即使你设置了强制,审核也不会通过

王志鹏:

现在不是只能用户点击才能引导去授权 不能主动弹授权框了

村上植树:好的感谢
村上植树:

由于项目需要用户开启小程序后检测如果没有授权则自动拉起授权页面,目的也是尽量避免相关功能无法使用,但是已经无法自动拉起授权了,那么只能是引导用户去授权,在原来调用授权的地方修改成对话框的形式

                    console.log('向用户发起授权请求 scope.userInfo')                    wx.showModal({                        title'小贴士',                        content'如果要体验完整的功能,需要点击获取头像昵称来授权小程序使用哦',                        showCancel: false,                        confirmText'已知悉',                        success (res) {                            // ...                        }                     })


也只能想到这种方法了,如果有更好的方法也可继续在底下评论,感谢大家百忙之中的回复

-EOF-