收藏
回答

无法获取用户头像等信息

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug open-type="getUserInfo" 工具 6.7.0 2.2.5

<!-- 如果只是展示用户头像昵称,可以使用 <open-data /> 组件 -->
<open-data type="userAvatarUrl"></open-data>
<open-data type="userNickName"></open-data>
<!-- 需要使用 button 来授权登录 -->
<button open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">授权登录</button>


//index.js
//获取应用实例
const app = getApp()
 
Page({
   data: {
      motto: 'Hello World',
      userInfo: {},
      hasUserInfo: false,
      canIUse: wx.canIUse('button.open-type.getUserInfo')
   },
 
   onLoad: function () {
      // 查看是否授权
      wx.getSetting({
         success(res) {
            if (res.authSetting['scope.userInfo']) {
               // 已经授权,可以直接调用 getUserInfo 获取头像昵称
               wx.getUserInfo({
                  success: function (res) {
                     console.log(res.userInfo)
                     var str = JSON.stringify(res.userInfo);
                     app.alertHui(str, function () { //回调弹窗
 
                     })
 
                  }
               })
            }
         }
      })
   },
   bindGetUserInfo: function (e) {
      console.log(e)
      app.globalData.userInfo = e.detail.userInfo;
      var str = JSON.stringify(e.detail.userInfo)
      app.alertHui(str, function () {  //回调弹窗
 
      })
 
   }
})



- 当前 Bug 的表现(可附上截图)





- 预期表现


- 复现路径


- 提供一个最简复现 Demo


最后一次编辑于  2018-09-17
回答关注问题邀请回答
收藏

2 个回答

  • 灵芝
    灵芝
    2018-09-17

    你好,请提供出现问题的机型和微信版本,以及能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

    2018-09-17
    有用
    回复 3
    • 小小人物
      小小人物
      2018-09-17

      代码片段示例




      小米手机型号:HM NOTE 1S


      手机版本:MIUI9.2稳定版


      微信版本 : 6.6.7

      2018-09-17
      回复
    • 晴天
      晴天
      2018-09-19

      借楼一用  

      点我看看

      2018-09-19
      回复
    • Allen
      Allen
      2018-10-04

      开发工具 里面的真机测试  是正常的 , 体验版 和线上都不行

      2018-10-04
      回复
  • 2018-09-17

    我也遇到过。。。是不是新接口不行啊?

    2018-09-17
    有用
    回复
登录 后发表内容