uniapp Douyin authorization to log in, publish, share Ba-Aweme

Introduction ( download address )

Ba-Aweme is a uniapp plug-in integrated with TikTok, which supports TikTok authorized login, publishing pictures and videos, sharing to contact groups, direct shooting, etc. It comes with the method of selecting pictures and selecting videos.

Note: Before using, first go to the Douyin open platform and apply for clientKey

screenshot display

insert image description here
insert image description here

Instructions

scriptIntroduce components in

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

Called in script(example reference, you can modify it according to your own business and calling method)

		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 list

method name illustrate
init initialization
sendAuth Authorized login
shareImage Share and publish (old shared single image/multiple images)
shareImageN Share and publish (newly share single image/multiple image support to open the atlas mode; need to upgrade to 0.1.9.4 or above)
shareVideo share video
isAppSupportMixShare Whether to support mixed sharing
shareMix Share mixed content (requires SDK version at least 0.1.7.0, Douyin version at least 17.4)
shareToContacts Share with Douyin friends or groups (only one picture can be passed in, currently only supports single picture and is a local picture)
shareToContactsHtml Share with Douyin friends or groups (html)
openRecordPage Open the Douyin shooting page
chooseSysImage Select picture (system)
chooseSysVideo Select Video (System)

init method parameters

attribute name type required Defaults illustrate
clientkey String true key, you need to apply on the developer website

sendAuth method parameters

attribute name type required Defaults illustrate
scope String true ‘user_info’ The authorized domain refers to what information your app can obtain from Douyin users after using TikTok authorization. Currently, the user_info authorized domain is open, which means that you can obtain permission to request user avatars, nicknames and other related information. If there are multiple mandatory permissions , please use commas to separate permissions, "xxx,xxx".
state String false It is used to keep the state of the request and callback, and bring it back to the third party as it is after the request is authorized, and any String can be passed.
optionalScope0 String false ‘mobile’ The user can select the authorized domain, which is not checked by default.
optionalScope1 String false The user can select the authorized domain, which is checked by default.

shareImage method parameters

attribute name type required Defaults illustrate
imagePaths Array true Local image path, can be multiple, such as: ['path1', 'path2']
hashTagList Array false Topic, supports multiple, such as: ['topic 1', 'topic 2']
state String false It is used to keep the state of the request and callback, and bring it back to the third party as it is after the request is authorized, and any String can be passed.

shareImageN method parameters

attribute name type required Defaults illustrate
imagePaths Array true Local image path, can be multiple, such as: ['path1', 'path2']
hashTagList Array false Topic, supports multiple, such as: ['topic 1', 'topic 2']
state String false It is used to keep the state of the request and callback, and bring it back to the third party as it is after the request is authorized, and any String can be passed.
isImageAlbum String false false Whether to enable gallery mode

shareVideo method parameters

attribute name type required Defaults illustrate
videoPaths Array true Local video path, can be multiple, such as: ['path1', 'path2']
hashTagList Array false Topic, supports multiple, such as: ['topic 1', 'topic 2']
state String false It is used to keep the state of the request and callback, and bring it back to the third party as it is after the request is authorized, and any String can be passed.

shareMix method parameters

attribute name type required Defaults illustrate
mixPaths Array true Local video and picture path, can be multiple, such as: ['path1', 'path2']
hashTagList Array false Topic, supports multiple, such as: ['topic 1', 'topic 2']
state String false It is used to keep the state of the request and callback, and bring it back to the third party as it is after the request is authorized, and any String can be passed.

shareToContacts method parameters

attribute name type required Defaults illustrate
imagePaths Array true Local image path, single, such as: ['path 1']
state String false It is used to keep the state of the request and callback, and bring it back to the third party as it is after the request is authorized, and any String can be passed.

shareToContactsHtml method parameters

attribute name type required Defaults illustrate
html String true Your html link (required)
description String true Your html description (required)
html String true Your html title (required)
html String false The cover image of your html (remote image) (optional, if not filled, use the icon uploaded when applying on the official website of the open platform)
state String false It is used to keep the state of the request and callback, and bring it back to the third party as it is after the request is authorized, and any String can be passed.

openRecordPage method parameters

attribute name type required Defaults illustrate
appTitle String false applet title
appTitle String false describe
appTitle String false Mini Program AppId
appTitle String false Applet path
state String false It is used to keep the state of the request and callback, and bring it back to the third party as it is after the request is authorized, and any String can be passed.

Series plug-ins

Image picker plugin Ba-MediaPicker ( documentation )

Image editing plugin Ba-ImageEditor ( documentation )

File picker plugin Ba-FilePicker ( documentation )

应用消息通知插件(多种样式,新增支持常驻通知模式) 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文档

Floating window (displayed on top of other applications) Ba-FloatWindow ( documentation )

Floating window (in-app, no authorization required) Ba-FloatWindow2 ( documentation )

Floating window (floating ball, dynamic menu, display on top of other applications) Ba-FloatBall ( documentation )

Added to "Open with other apps" for file delivery, sharing, etc. Ba-ShareReceive ( documentation )

Get Map Data (Geocode, Geocoding, Anti-Geocoding) Ba-AMapData ( documentation )

Caller ID floating window plug-in (support lock screen) Ba-CallerID ( documentation )

Guess you like

Origin blog.csdn.net/u013164293/article/details/130432981