【小程序】报getUserProfile:fail can only be invoked by user TAP gesture.

最近新搭建了个小程序项目,登录时报getUserProfile:fail can only be invoked by user TAP gesture.这个错误。查了网上说的是使用了async和await,试着改了不用async和await,结果还是一样报这个错误。

我的代码是用户点击授权按钮后,先使用wx.login,接着后面使用wx.getUserProfile,在同一个方法里执行。试着将wx.login注释,结果wx.getUserProfile正常获取到结果。也就是说wx.login和wx.getUserProfile不能在同一时间去获取。

知道原因之后就好办了,将wx.login移到了授权组件的mounted方法,并将code保存

mounted(){
	wx.login({
		success:(res) => {
			this.code = res.code
		}
	})
},

点击授权按钮后还是使用了async/await去获取用户信息,兼容了getUserProfile和getUserInfo

actionLogin: async function(res) {
    // 原本在这里调用getWxCode的wx.login获取code的
    // const resCode = await this.getWxCode()
	const resUser = await this.getUserInfo()
	this.getOpenid(resUser)    // 拿到了code和个人信息就可以调后端接口登录了
},

// 适配新旧版本获取个人信息
getUserInfo: async function() {
	// wx.getUserProfile
	if(wx.getUserProfile){
		return new Promise((resolve, reject) => {
			wx.getUserProfile({
				lang: "zh_CN",
				desc: '用于完善会员资料',
				success: (res) => {
					resolve(res)
				}
                // 失败回调根据自己项目去设计
            })
        })
	}
	// wx.getUserInfo
	else{
		return new Promise((resolve, reject) => {
			wx.getUserInfo({
				provider: 'weixin',
				lang: "zh_CN",
				success: (res) => {
					resolve(res)
				}
                // 失败回调根据自己项目去设计
			})
		})
	}
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
32位版本的 PLSQL 正式版, 安装中文包时请注意安装路径是否为PLSQL程序的路径。 备注:新版本Ribbon启用了 Ribbon 界面,改动较大,不习惯的建议不要更新。 部分插件会加载失败。 New features Ribbon User Interface PL/SQL Developer now uses a new Ribbon User Interface instead of a Menu User Interface: The Quick Access Toolbar above the ribbon contains the most frequently used functions, so that they are always immediately available. You can customize the Quick Access Toolbar to your own liking. Users that prefer a menu-like system to preserve screen real estate can select to automatically hide the ribbon. In the preferences you can select an option to revert to the familiar toolbar layout from PL/SQL Developer 11.0 and earlier. Single Document Interface On the "View" ribbon you can now choose between a Single Document Interface (SDI) or Multiple Document Interface (MDI - the same as in PL/SQL Developer 11.0 and earlier). In SDI mode you always see just one maximized window. A tab control above the window allows you to quickly switch between the windows: General User Interface Enhancements PL/SQL Developer is now fully compliant with High-DPI screens such as 4K monitors and notebooks. All controls and images will scale with resolution (some Plug-Ins may still need to be enhanced). Click on the image below to enlarge this example of a 15" 4K notebook (250% DPI): All window types now have a specific icon color, so that you can quickly identify the type in the Window List, in the SDI tab control, in the window titles, and so on. The transaction status is now visible in the status bar of a window, next to the "Saved" and "Executing" indicators. Added user interface preference "Preselect current user for object selection lists". PL/SQL Clipboard The new PL/SQL Clipboard is a dockable tool that stores the history of all SQL and PL/SQL code you copy to the Windows clipboard, so that you can paste the clipboard item again in the future. It has a filter function so that you can quickly find a clipboard item based on its contents: At the bottom you see the PL/SQL Clipboard history items. Clicking on an item will show the text with syntax highlighting in the preview pane, and will show the timestamp above the preview pane. Double-click on an item to paste the text in the cursor location of the current editor or drag & drop it to a specific location in an editor. You can use the editor preferences to configure when and how items are added to and deleted from the PL/SQL Clipboard. Debugger Enhancements You can now display compound variable values such as user-defined types, records and cursors: Support has been added for Error Breakpoints, which allow you to break execution when a specific exception (handled or unhandled) occurs: Breakpoints can now be saved and loaded. Debug object privileges can now be granted and revoked from the user interface. Code Assistant Enhancements The Code Assistant can now include column names from a DML statement context without using an alias: The Code Assistant can now describe sub-records. The Code Assistant now includes an <All> choice for default object type constructors. The Code Assistant can now include synonyms for user object lists. The Code Assistant no longer pre-selects <All> after typing part of a parameter/column name. SQL Window Enhancements A new preference has been added: "Null value cell color for mandatory columns". This allows you to quickly identify mandatory columns when adding new records: The result set selection can now be copied as an expression list: "column in (value, value, ...)" by right-clicking on a selection and selecting "Copy as expression list" from the popup menu. This allows you to quickly build a where clause based on the selection: When viewing or editing LOB's the contents for common data formats will automatically be recognized, so that an external viewer or editor can be invoked: Changes made and saved in an external editor will automatically be propagated to the column data. The SQL Window will now navigate to the offending cell in the result set after an insert or update with a column-specific error. The rowid column is now omitted when exporting a result set grid in SQL format. Test Window Enhancements You can now define Standard Tests for a specific function or procedure: A Standard Test can be invoked from the popup menu when right-clicking on the function or procedure in the Object Browser or in a PL/SQL source: The Test Window now supports Oracle12c implicit results, which are automatically detected and added to the variable list: A new Oracle / Output preference has been added to save dbms_output to a file. The filename can include %dbname%, %dbuser% and %date% variables to separate output files based on the database, user and date. Program Window Enhancements You can now suppress a hint or warning for a specific line of code by adding a "-- Ignore" comment. The Code Contents pane now shows local subprograms within a procedure/function in a separate folder. Session Window Enhancements The Session Window now has a Single Record View for the session details: You can now kill a session with the "immediate" option. Connection Enhancements A "Set current schema" item has been added to the connection popup menu. It will set the current schema for all windows of this connection. The current schema will be displayed in square brackets in the Connection List: Connecting through a proxy user is now supported. Other Enhancements A Compare function has been added to the Object Browser. You can compare program units, tables, views, sequences with sources in the database, in a file or in a window. A new Oracle / Options preference "Always include owner prefix" has been added. When enabled, DLL extracted from the database will always include the owner prefix. When disabled, the owner will be omitted if you are connected as the owner. A new "Stop" item has been added to the DBMS Scheduler "Running job" popup menu. Support has been added for Oracle12c read privileges for tables and views. Scripts generated by Export User Objects and Export Tables now have user-defined initialization and finalization. These files are located in the %APPDATA%\PLSQL Developer 12\Scripts directory. The Text Importer and ODBC Importer can now also truncate a table before import, in addition to the "Delete" option. The truncate option is faster but cannot be rolled back. The Compile Invalid Objects tool now has a User Selector. PL/SQL Developer 12 now comes as a new MSI installer for interactive and silent installation.
"getUserProfile:fail can only be invoked by user TAP gesture."的错误通常是因为在调用wx.getUserProfile方法时没有通过用户点击手势触发。这意味着在调用getUserProfile方法之前,需要将其绑定到一个点击事件上,确保只有用户点击后才能调用该方法。 另外,有些情况下,如果在wx.login方法中嵌套调用getUserProfile方法,也会导致这个错误的出现。所以需要确保在不同的时间段内调用这两个方法,而不是同时进行。 此外,有人提到使用async和await可能会出现这个错误。如果你在代码中使用了async和await,尝试将其去掉并使用其他方式来处理异步操作,看看是否还会出现相同的错误。 总结起来,解决这个错误的关键是确保在调用wx.getUserProfile方法时,通过用户点击手势触发,并且避免在wx.login方法中同时调用getUserProfile方法。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [uni.getUserProfile错:fail can only be invoked by user TAP gesture](https://blog.csdn.net/cwjxyp/article/details/122201261)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [【小程序getUserProfile:fail can only be invoked by user TAP gesture.](https://blog.csdn.net/qq_37451395/article/details/123579444)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值