uniapp 抖音授权登录、发布、分享 Ba-Aweme
簡介(下載地址)
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: "", //小程序titlediscription: "", //描述appId: "", //小程序AppIdappUrl: "", //小程序路徑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 方法參數
| clientkey | String | true | key,需要到開發者網站申請 |
sendAuth 方法參數
| scope | String | true | ‘user_info’ | 授權域是指您的應用使用抖音授權之后,可以獲得抖音用戶的哪些信息,目前開放了user_info 授權域,表示可以獲得請求用戶頭像、昵稱等相關信息的權限,如果有多種必選權限,權限之間請使用逗號隔開, “xxx,xxx”。 |
| state | String | false | 用于保持請求和回調的狀態,授權請求后原樣帶回給第三方,可傳任意 String。 | |
| optionalScope0 | String | false | ‘mobile’ | 用戶可選授權域,默認不勾選。 |
| optionalScope1 | String | false | 用戶可選授權域,默認勾選。 |
shareImage 方法參數
| imagePaths | Array | true | 本地圖片路徑,可多個,如:[‘路徑1’, ‘路徑2’] | |
| hashTagList | Array | false | 話題,支持多個,如:[‘話題1’, ‘話題2’] | |
| state | String | false | 用于保持請求和回調的狀態,授權請求后原樣帶回給第三方,可傳任意 String。 |
shareImageN 方法參數
| imagePaths | Array | true | 本地圖片路徑,可多個,如:[‘路徑1’, ‘路徑2’] | |
| hashTagList | Array | false | 話題,支持多個,如:[‘話題1’, ‘話題2’] | |
| state | String | false | 用于保持請求和回調的狀態,授權請求后原樣帶回給第三方,可傳任意 String。 | |
| isImageAlbum | String | false | false | 是否開啟圖集模式 |
shareVideo 方法參數
| videoPaths | Array | true | 本地視頻路徑,可多個,如:[‘路徑1’, ‘路徑2’] | |
| hashTagList | Array | false | 話題,支持多個,如:[‘話題1’, ‘話題2’] | |
| state | String | false | 用于保持請求和回調的狀態,授權請求后原樣帶回給第三方,可傳任意 String。 |
shareMix 方法參數
| mixPaths | Array | true | 本地視頻和圖片路徑,可多個,如:[‘路徑1’, ‘路徑2’] | |
| hashTagList | Array | false | 話題,支持多個,如:[‘話題1’, ‘話題2’] | |
| state | String | false | 用于保持請求和回調的狀態,授權請求后原樣帶回給第三方,可傳任意 String。 |
shareToContacts 方法參數
| imagePaths | Array | true | 本地圖片路徑,單個,如:[‘路徑1’] | |
| state | String | false | 用于保持請求和回調的狀態,授權請求后原樣帶回給第三方,可傳任意 String。 |
shareToContactsHtml 方法參數
| html | String | true | 你的html鏈接(必填) | |
| discription | String | true | 你的html描述(必填) | |
| html | String | true | 你的html title(必填) | |
| html | String | false | 你的html的封面圖(遠程圖片) (選填,若不填,則使用開放平臺官網申請時上傳的圖標) | |
| state | String | false | 用于保持請求和回調的狀態,授權請求后原樣帶回給第三方,可傳任意 String。 |
openRecordPage 方法參數
| appTitle | String | false | 小程序title | |
| appTitle | String | false | 描述 | |
| appTitle | String | false | 小程序AppId | |
| appTitle | String | false | 小程序路徑 | |
| state | String | false | 用于保持請求和回調的狀態,授權請求后原樣帶回給第三方,可傳任意 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(文檔)
總結
以上是生活随笔為你收集整理的uniapp 抖音授权登录、发布、分享 Ba-Aweme的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 服务网格——后 Kubernetes 时
- 下一篇: stm32驱动rgb屏电路图_stm32