uniapp 抖音授权登录、发布、分享 Ba-Aweme

Ba-Aweme是一个uniapp插件,支持抖音授权登录、图片视频分享、混合内容分享等功能。它提供了多种方法,如sendAuth进行授权,shareImage和shareVideo进行内容分享,以及openRecordPage打开抖音拍摄页等。
摘要由CSDN通过智能技术生成

简介(下载地址

Ba-Aweme 是一个集成抖音的uniapp插件,支持抖音授权登录,发布图片、视频,分享到联系人群组,直接拍摄等。自带选择图片和选择视频方法。

注意: 使用前,先到抖音开放平台,申请clientKey

截图展示

在这里插入图片描述
在这里插入图片描述

使用方法

script 中引入组件

	const aweme = uni.requireNativePlugin('Ba-Aweme');

script 中调用(示例参考,可根据自己业务和调用方法自行修改)

		methods: {
			init() { //初始化
				aweme.init({
						clientkey: 'awsxdh3k1fiojgnu' // 需要到开发者网站申请
					},
					(res) => {
						console.log(res)
						uni.showToast({
							title: res.msg,
							icon: "none",
							duration: 3000
						})
					});
			},
			sendAuth() { //授权登录
				aweme.sendAuth({
						scope: 'user_info', //授权域是指您的应用使用抖音授权之后,可以获得抖音用户的哪些信息,目前开放了user_info 授权域,表示可以获得请求用户头像、昵称等相关信息的权限,如果有多种必选权限,权限之间请使用逗号隔开, "xxx,xxx"。
						state: '', //用于保持请求和回调的状态,授权请求后原样带回给第三方,可传任意 String。
						optionalScope0: '', //用户可选授权域,默认不勾选。
						optionalScope1: '', //用户可选授权域,默认勾选。
					},
					(res) => {
						console.log(res)
						if (res.data) {
							this.msgList.push(JSON.stringify(res.data));
						}
						uni.showToast({
							title: res.msg,
							icon: "none",
							duration: 3000
						})
					});
			},
			isAppSupportMixShare() { //是否支持了图片视频混合内容的分享(抖音版本 17.4)
				aweme.isAppSupportMixShare(
					(res) => {
						console.log(res)
						if (res.data) {
							this.msgList.push(JSON.stringify(res.data));
						} else {
							uni.showToast({
								title: res.msg,
								icon: "none",
								duration: 3000
							})
						}
					});
			},
			shareImage() { //分享图片
				aweme.shareImage({
						imagePaths: this.mediaPaths, //图片路径,可多个
						hashTagList: ['话题1', '话题2'], //默认话题
						state: 'ww',
					},
					(res) => {
						console.log(res)
						if (res.data) {
							this.msgList.push(JSON.stringify(res.data));
						} else {
							uni.showToast({
								title: res.msg,
								icon: "none",
								duration: 3000
							})
						}
					});
			},
			shareImageN() { //分享发布(新分享单图/多图 支持开启图集模式;需升级到0.1.9.4以上)
				aweme.shareImageN({
						imagePaths: this.mediaPaths, //图片路径,可多个
						hashTagList: ['话题1', '话题2'], //默认话题
						state: 'ww',
						isImageAlbum: true, //是否开启图集模式
					},
					(res) => {
						console.log(res)
						if (res.data) {
							this.msgList.push(JSON.stringify(res.data));
						} else {
							uni.showToast({
								title: res.msg,
								icon: "none",
								duration: 3000
							})
						}
					});
			},
			shareVideo() { //分享视频
				aweme.shareVideo({
						videoPaths: this.mediaPaths, //视频路径,可多个
						hashTagList: ['话题1', '话题2'], //默认话题
						state: 'ww',
					},
					(res) => {
						console.log(res)
						if (res.data) {
							this.msgList.push(JSON.stringify(res.data));
						} else {
							uni.showToast({
								title: res.msg,
								icon: "none",
								duration: 3000
							})
						}
					});
			},
			shareMix() { //分享混合内容(要求SDK版本至少为0.1.7.0,抖音版本至少为17.4)
				aweme.shareMix({
						mixPaths: this.mediaPaths, //路径,可多个
						hashTagList: ['话题1', '话题2'], //默认话题
						state: 'ww',
					},
					(res) => {
						console.log(res)
						if (res.data) {
							this.msgList.push(JSON.stringify(res.data));
						} else {
							uni.showToast({
								title: res.msg,
								icon: "none",
								duration: 3000
							})
						}
					});
			},
			shareToContacts() { //分享给抖音好友或群(注意: 只能传入一张图片,目前只支持单图且为本地图片
				aweme.shareToContacts({
						imagePaths: this.mediaPaths, //图片
						state: 'ww',
					},
					(res) => {
						console.log(res)
						if (res.data) {
							this.msgList.push(JSON.stringify(res.data));
						} else {
							uni.showToast({
								title: res.msg,
								icon: "none",
								duration: 3000
							})
						}
					});
			},
			shareToContactsHtml() { //分享给抖音好友或群(html)
				aweme.shareToContactsHtml({
						html: "", //你的html链接(必填)
						discription: "", //你的html描述(必填)
						title: "", //你的html  title(必填)
						thumbUrl: "", //你的html的封面图(远程图片) (选填,若不填,则使用开放平台官网申请时上传的图标)
						state: 'ww',
					},
					(res) => {
						console.log(res)
						if (res.data) {
							this.msgList.push(JSON.stringify(res.data));
						} else {
							uni.showToast({
								title: res.msg,
								icon: "none",
								duration: 3000
							})
						}
					});
			},
			openRecordPage() { //打开抖音拍摄页
				aweme.openRecordPage({
						appTitle: "", //小程序title
						discription: "", //描述
						appId: "", //小程序AppId
						appUrl: "", //小程序路径
						state: '',
					},
					(res) => {
						console.log(res)
						if (res.data) {
							this.msgList.push(JSON.stringify(res.data));
						} else {
							uni.showToast({
								title: res.msg,
								icon: "none",
								duration: 3000
							})
						}
					});
			},
			chooseSysImage() { //选择图片(系统)
				aweme.chooseSysImage(
					(res) => {
						console.log(res)
						if (res.data) {
							this.msgList.push(JSON.stringify(res.data));
						} else {
							uni.showToast({
								title: res.msg,
								icon: "none",
								duration: 3000
							})
						}
					});
			},
			chooseSysVideo() { //选择视频(系统)
				aweme.chooseSysVideo(
					(res) => {
						console.log(res)
						if (res.data) {
							this.msgList.push(JSON.stringify(res.data));
						} else {
							uni.showToast({
								title: res.msg,
								icon: "none",
								duration: 3000
							})
						}
					});
			},
			chooseImage() { //选择图片(uniapp)
				let that = this;
				uni.chooseImage({
					count: 9,
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
					sourceType: ['album'], //从相册选择
					success: function(res) {
						console.log(JSON.stringify(res.tempFilePaths));
						that.mediaPaths = res.tempFilePaths;
						// uni.getImageInfo({
						// 	src: res.tempFilePaths[0],
						// 	success: function(image) {
						// 		that.path = image.path;
						// 		console.log(image);
						// 	}
						// });
					}
				})
			},
			chooseVideo() { //选择视频(uniapp)
				let that = this;
				uni.chooseVideo({
					sourceType: ['camera', 'album'],
					success: function(res) {
						console.log(JSON.stringify(res.tempFilePath));
						that.mediaPaths.push(res.tempFilePath);
					}
				})
			},
		}

api 列表

方法名说明
init初始化
sendAuth授权登录
shareImage分享发布(旧分享单图/多图)
shareImageN分享发布(新分享单图/多图 支持开启图集模式;需升级到0.1.9.4以上)
shareVideo分享视频
isAppSupportMixShare是否支持混合分享
shareMix分享混合内容(要求SDK版本至少为0.1.7.0,抖音版本至少为17.4)
shareToContacts分享给抖音好友或群(只能传入一张图片,目前只支持单图且为本地图片)
shareToContactsHtml分享给抖音好友或群(html)
openRecordPage打开抖音拍摄页
chooseSysImage选择图片(系统)
chooseSysVideo选择视频(系统)

init 方法参数

属性名类型必填默认值说明
clientkeyStringtruekey,需要到开发者网站申请

sendAuth 方法参数

属性名类型必填默认值说明
scopeStringtrue‘user_info’授权域是指您的应用使用抖音授权之后,可以获得抖音用户的哪些信息,目前开放了user_info 授权域,表示可以获得请求用户头像、昵称等相关信息的权限,如果有多种必选权限,权限之间请使用逗号隔开, “xxx,xxx”。
stateStringfalse用于保持请求和回调的状态,授权请求后原样带回给第三方,可传任意 String。
optionalScope0Stringfalse‘mobile’用户可选授权域,默认不勾选。
optionalScope1Stringfalse用户可选授权域,默认勾选。

shareImage 方法参数

属性名类型必填默认值说明
imagePathsArraytrue本地图片路径,可多个,如:[‘路径1’, ‘路径2’]
hashTagListArrayfalse话题,支持多个,如:[‘话题1’, ‘话题2’]
stateStringfalse用于保持请求和回调的状态,授权请求后原样带回给第三方,可传任意 String。

shareImageN 方法参数

属性名类型必填默认值说明
imagePathsArraytrue本地图片路径,可多个,如:[‘路径1’, ‘路径2’]
hashTagListArrayfalse话题,支持多个,如:[‘话题1’, ‘话题2’]
stateStringfalse用于保持请求和回调的状态,授权请求后原样带回给第三方,可传任意 String。
isImageAlbumStringfalsefalse是否开启图集模式

shareVideo 方法参数

属性名类型必填默认值说明
videoPathsArraytrue本地视频路径,可多个,如:[‘路径1’, ‘路径2’]
hashTagListArrayfalse话题,支持多个,如:[‘话题1’, ‘话题2’]
stateStringfalse用于保持请求和回调的状态,授权请求后原样带回给第三方,可传任意 String。

shareMix 方法参数

属性名类型必填默认值说明
mixPathsArraytrue本地视频和图片路径,可多个,如:[‘路径1’, ‘路径2’]
hashTagListArrayfalse话题,支持多个,如:[‘话题1’, ‘话题2’]
stateStringfalse用于保持请求和回调的状态,授权请求后原样带回给第三方,可传任意 String。

shareToContacts 方法参数

属性名类型必填默认值说明
imagePathsArraytrue本地图片路径,单个,如:[‘路径1’]
stateStringfalse用于保持请求和回调的状态,授权请求后原样带回给第三方,可传任意 String。

shareToContactsHtml 方法参数

属性名类型必填默认值说明
htmlStringtrue你的html链接(必填)
discriptionStringtrue你的html描述(必填)
htmlStringtrue你的html title(必填)
htmlStringfalse你的html的封面图(远程图片) (选填,若不填,则使用开放平台官网申请时上传的图标)
stateStringfalse用于保持请求和回调的状态,授权请求后原样带回给第三方,可传任意 String。

openRecordPage 方法参数

属性名类型必填默认值说明
appTitleStringfalse小程序title
appTitleStringfalse描述
appTitleStringfalse小程序AppId
appTitleStringfalse小程序路径
stateStringfalse用于保持请求和回调的状态,授权请求后原样带回给第三方,可传任意 String。

系列插件

图片选择插件 Ba-MediaPicker文档

图片编辑插件 Ba-ImageEditor文档

文件选择插件 Ba-FilePicker文档

应用消息通知插件(多种样式,新增支持常驻通知模式) Ba-Notify文档

自定义通知(耳机电量)插件 Ba-NotifyEarphone文档

应用未读角标插件 Ba-Shortcut-Badge文档

应用开机自启插件 Ba-Autoboot文档

扫码原生插件(毫秒级、支持多码)Ba-Scanner-G文档

扫码原生插件 - 新(可任意自定义界面版本;支持连续扫码;支持设置扫码格式)Ba-Scanner文档

动态修改状态栏、导航栏背景色、字体颜色插件 Ba-AppBar文档

原生sqlite本地数据库管理 Ba-Sqlite文档

安卓保活插件(采用多种主流技术) Ba-KeepAlive文档

安卓保活套装(通用、常驻通知、电池优化、自启管理、后台运行等)文档

安卓快捷方式(桌面长按app图标) Ba-Shortcut文档

自定义图片水印(任意位置) Ba-Watermark文档

最接近微信的图片压缩插件 Ba-ImageCompressor文档

视频压缩、视频剪辑插件 Ba-VideoCompressor文档

动态切换应用图标、名称(如新年、国庆等) Ba-ChangeIcon文档

原生Toast弹窗提示(穿透所有界面、穿透原生;自定义颜色、图标 ) Ba-Toast文档

图片涂鸦、画笔 Ba-ImagePaint文档

pdf阅读(手势缩放、显示页数) Ba-Pdf文档

声音提示、震动提示、语音播报 Ba-Beep文档

websocket原生服务(自动重连、心跳检测) Ba-Websocket文档

短信监听(验证码) Ba-Sms文档

智能安装(自动升级) Ba-SmartUpgrade文档

监听系统广播、自定义广播 Ba-Broadcast文档

监听通知栏消息(支持白名单、黑名单、过滤) Ba-NotifyListener文档

全局置灰、哀悼置灰(可动态、同时支持nvue、vue) Ba-Gray文档

获取设备唯一标识(OAID、AAID、IMEI等) Ba-IdCode文档

实时定位(系统、后台运行、支持息屏)插件 Ba-Location文档

实时定位(高德、后台运行、支持息屏、坐标转换、距离计算) Ba-LocationAMap文档

窗口小工具、桌面小部件、微件 Ba-AppWidget文档

窗口小工具、桌面小部件、微件(日历、时间) Ba-AwCalendarS文档

画中画悬浮窗(视频) Ba-VideoPip文档

悬浮窗(在其他应用上层显示) Ba-FloatWindow文档

悬浮窗(应用内、无需授权) Ba-FloatWindow2文档

悬浮窗(悬浮球、动态菜单、在其他应用上层显示) Ba-FloatBall文档

添加到“用其他应用打开”中,用于文件传递、分享等 Ba-ShareReceive文档

获取地图数据(高德、地理编码、反地理编码) Ba-AMapData文档

来电显示悬浮窗插件(支持锁屏) Ba-CallerID文档

  • 5
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值