更新记录
1.0.1(2025-03-19)
修改引用包
1.0.0(2025-03-19)
Google登录/登出功能,ios规划中
平台兼容性
Vue2 | Vue3 |
---|---|
√ | × |
App | 快应用 | 微信小程序 | 支付宝小程序 | 百度小程序 | 字节小程序 | QQ小程序 |
---|---|---|---|---|---|---|
HBuilderX 4.43,Android:不确定,iOS:不支持,HarmonyNext:不确定 | × | × | × | × | × | × |
钉钉小程序 | 快手小程序 | 飞书小程序 | 京东小程序 | 鸿蒙元服务 |
---|---|---|---|---|
× | × | × | × | × |
H5-Safari | Android Browser | 微信浏览器(Android) | QQ浏览器(Android) | Chrome | IE | Edge | Firefox | PC-Safari |
---|---|---|---|---|---|---|---|---|
× | × | × | × | × | × | × | × | × |
uni-oauth-google
使用说明
关于 Credential Manager
Credential Manager 是Android 最新的登录鉴权方式.本插件基于Credential Manager
实现了Google登录功能
创建 google cloud 应用
在google云管理后台,创建应用,并创建OAuth 客户端 ID
,重点确保填写正确的包名和证书签名。
创建完成后,保存客户端ID
用于代码调用。客户端ID
的格式:xxxxx.apps.googleusercontent.com
调用代码
以正确的包名和证书自定义基座后,可以使用下面的代码进行调用
uvue:
<template>
<view>
<button @tap="loginClick" >google登录</button>
<button @tap="logoutClick" >google登出</button>
</view>
</template>
<script>
import { googleLogin, GoogleLoginOptions } from "@/uni_modules/uni-oauth-google"
import { googleLogout, GoogleLogoutOptions } from "@/uni_modules/uni-oauth-google"
export default {
data() {
return {
}
},
methods: {
loginClick:()=>{
let options = {
serverClientId:"xxxxx.apps.googleusercontent.com",
success: (res : any) => {
console.log("success",res)
},
fail: (res : any) => {
console.log("fail",res)
},
complete: (res : any) => {
console.log("complete",res)
}
} as GoogleLoginOptions;
googleLogin(options);
},
logoutClick:()=>{
let options = {
success: (res : any) => {
console.log("success",res)
},
fail: (res : any) => {
console.log("fail",res)
},
complete: (res : any|null) => {
console.log("complete",res)
}
} as GoogleLogoutOptions;
googleLogout(options);
}
}
}
</script>
<style>
</style>
vue:
<template>
<view>
<button @tap="loginClick" >google登录</button>
<button @tap="logoutClick" >google登出</button>
</view>
</template>
<script>
import { googleLogin } from "@/uni_modules/uni-oauth-google"
import { googleLogout } from "@/uni_modules/uni-oauth-google"
export default {
data() {
return {
}
},
methods: {
loginClick:()=>{
let options = {
serverClientId:"xxxxxxxx.apps.googleusercontent.com",
success: (res) => {
console.log("success",res)
},
fail: (res) => {
console.log("fail",res)
},
complete: (res) => {
console.log("complete",res)
}
}
googleLogin(options);
},
logoutClick:()=>{
let options = {
success: () => {
console.log("success")
},
fail: (res) => {
console.log("fail",res)
},
complete: (res) => {
console.log("complete",res)
}
}
googleLogout(options);
},
}
}
</script>
<style>
</style>
错误码说明
代码 | 说明 |
---|---|
9010001 | 系统环境错误,请检查application/activity状态 |
9010002 | 用户参数配置错误,重点检查serverClientId是否正确 |
9010003 | 暂不支持的登录凭据 |
9010004 | 无法找到对应的凭据,可能是应用签名/包名不匹配或者与Google连接失败 |
9010005 | 登录组件缺失,请检查系统是否正确安装GMS |
9010000 | 其他未知错误 |