求助:原来用的是getUserInfo,怎么改成getUserProfile?
发布于 5 年前 作者 tao37 3860 次浏览 来自 官方Issues

求助:原来用的是getUserInfo,怎么改成getUserProfile?用下面的代码,按钮点了没反映,调用不了微信头像。

wxml:

<button open-type="getUserInfo"  bindgetuserinfo="bindGetUserInfo" class="btn">使用微信头像</button>

js:

bindGetUserInfo (e) {
	    const that = this 
		wx.getUserProfile({   		
			success (res){     
	          if (res.authSetting['scope.userInfo']) { 	            
	            wx.getUserInfo({   
	              success: function(res) {  
				       wx.downloadFile({   
	                    url: res.userInfo.avatarUrl, 
	                    success (res) {              
	                        console.log(res.tempFilePath) 
	                      if (res.statusCode === 200) {   
	                        that.setData({                
	                            imgg:res.tempFilePath    
	                        })
	                        that.create()
	                      }
	                    }
	                })
	                
	              }
	            })
	          }
	        }
	    })
	},

   

3 回复
wx.getUserProfile 获取用户信息的这个API不会给你返回用户的授权信息的 你的代码问题 去掉就行了

还有这两个API不要同时调用

<view bindtap="bindGetUserProfile">点击</view>
bindGetUserProfile() {
	    const that = this 
		wx.getUserProfile({
                 desc:'测试'  		
  		 success (res){     
	       console.log(res)
    	      }
	    })
	},
回到顶部