大家使用uniapp+vue3,接入抖音登录,使用的是什么方式呢?
我用【方法1】:
<button
class="btn_toutiao"
open-type="getUserInfo"
@getuserinfo="handleGetUserInfo"
:disabled="!toutiaoAgreed"
>
抖音一键注册/登录
</button>
const handleGetUserInfo = (e) => {
if (!toutiaoAgreed.value) {
uni.showToast({ title: '请先同意服务协议和隐私政策', icon: 'none' })
return
}
const { detail } = e
// 检查授权结果
if (detail.errMsg !== 'getUserInfo:ok') {
uni.showToast({ title: '授权失败,请重试', icon: 'none' })
return
}
const { code, userInfo } = detail
if (!code) {
uni.showToast({ title: '获取登录凭证失败', icon: 'none' })
return
}
// 执行登录
//...
}【方法2】:
<view
class="btn_toutiao"
:class="{ disabled: !toutiaoAgreed }"
@tap="handleToutiaoGetUserInfo"
>
抖音一键注册/登录
</view>
const handleToutiaoGetUserInfo = function () {
// #ifdef MP-TOUTIAO
if (!toutiaoAgreed.value) {
uni.showToast({
title: '请先阅读并同意服务协议和隐私政策',
icon: 'none',
})
return
}
tt.getUserProfile({
force: true,
success(res) {
console.log('抖音用户授权成功:', res)
const { userInfo } = res
toutiaoUserInfo.value = userInfo
doToutiaoLogin()
},
fail(err) {
console.error('抖音用户授权失败:', err)
if (err.errMsg && err.errMsg.includes('auth deny')) {
uni.showToast({
title: '您拒绝了用户授权',
icon: 'none',
})
}
else {
uni.showToast({
title: '授权失败,请重试',
icon: 'none',
})
}
},
})
// #endif
}
都提示这个:
tma-core.js:2 [getUserProfile] 自2023年6月6日起,平台会对用户授权页面进行严格审核,请务必确保你的登录流程符合平台规范,详见:https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/operation/management/specification/zhanghaodenglu tma-core.js:2 [TMA] APIScopeError: must be invoked by user tap gesture at oc(http://127.0.0.1:7044/core/4.12.0.3/tma-core.js:2:115880) at Proxy.<anonymous>(http://127.0.0.1:7044/core/4.12.0.3/tma-core.js:2:315962) at ?(http://127.0.0.1:7044/core/4.12.0.3/tma-core.js:2:1117554) at Generator.<anonymous>(http://127.0.0.1:7044/core/4.12.0.3/tma-core.js:2:44119) at Generator.next(http://127.0.0.1:7044/core/4.12.0.3/tma-core.js:2:44963) at Ja(http://127.0.0.1:7044/core/4.12.0.3/tma-core.js:2:40912) at i(http://127.0.0.1:7044/core/4.12.0.3/tma-core.js:2:41115) at ?(http://127.0.0.1:7044/core/4.12.0.3/tma-core.js:2:41176) at new Promise(<anonymous>) at ?(http://127.0.0.1:7044/core/4.12.0.3/tma-core.js:2:41056) AI助手 wxlogin.js? [sm]:83 抖音用户授权失败: {errMsg: "getUserProfile:fail must be invoked by user tap gesture", errNo: 21500, errorCode: 111601, errorType: "D"}
请问是什么原因呢?
