更新记录

1.0.0(2024-08-30)

初次提交


平台兼容性

Vue2 Vue3
×
App 快应用 微信小程序 支付宝小程序 百度小程序 字节小程序 QQ小程序
Android:不确定,iOS:不确定 × × × × × ×
钉钉小程序 快手小程序 飞书小程序 京东小程序
× × × ×
H5-Safari Android Browser 微信浏览器(Android) QQ浏览器(Android) Chrome IE Edge Firefox PC-Safari
× × × × × × × × ×

抖音Android移动端SDK原生集成(抖音第三方授权登录分享)插件

配置抖音AppID

在AndroidManifest.xml中修改AppID
<meta-data android:name="DouyinAppID" android:value="请填入安卓端抖音AppID" />

引用插件

import {
    isDouyinAppInstalled,
    isDouyinLiteAppInstalled,
    isDouyinHTSAppInstalled,
    onAuthorize,
    onShare,
    onShareContentToIM,
    onOpenCapture
} from '@/uni_modules/u-douyin-api'

方法调用

1、判断移动客户是否安装

//>判断是否安装抖音
var isInstalledDouyin = isDouyinAppInstalled()
console.log("是否安装了抖音:" + isInstalledDouyin)

//>判断是否安装抖音极速版
var isInstalledDouyinLite = isDouyinLiteAppInstalled()
console.log("是否安装了抖音极速版:" + isInstalledDouyinLite)

//>判断是否安装抖音火山版
var isInstalledDouyinHTS = isDouyinHTSAppInstalled()
console.log("是否安装了抖音火山版:" + isInstalledDouyinHTS)

2、抖音授权登录

onAuthorize({
    scope: "user_info", //"user_info,trial.whitelist" 用户授权时必选权限
    state: "",
    success: function(response) {
        console.log("登录受权success:", response);
    },
    fail: function(err) {
        console.log("登录受权fail:", err);
    }
})

3、发布抖音

share1() {
    //发布抖音传打开相册选择
    var that = this
    if (uni.getSystemInfoSync().platform == 'android') {
        //视频
        // uni.chooseVideo({
        //  count: 1,
        //  sourceType: ['album'],
        //  success(res) {
        //      that.shareWithMediaIds([plus.io.convertLocalFileSystemURL(res.tempFilePath)], "ShareMediaTypeVideo")
        //  }
        // })
        //图片
        uni.chooseImage({
            count: 12,
            sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
            sourceType: ['album'], //从相册选择
            success: function(res) {
                var paths = [];
                for (var i = 0; i < res.tempFilePaths.length; i++) {
                    var url = res.tempFilePaths[i];
                    paths[i] = plus.io.convertLocalFileSystemURL(url);
                }
                that.shareWithMediaIds(paths, "ShareMediaTypeImage")
            }
        });
    }
},
shareWithMediaIds(media, MediaType) {
    //>发布抖音(传imagePaths)
    onShare({
        params: {
            shareMediaType: MediaType, //可选参数有:ShareMediaTypeVideo、ShareMediaTypeImage
            // imageAlbumMode: true, //当shareMediaType==ShareMediaTypeImage默认生成图片视频。如果要设置生成图集,把imageAlbumMode设置为true
            state: "",
            imagePaths: media,

            /*,
            shareToPublish:true,//直接分享到抖音发布页,分享到发布页目前只支持单视频发布。
            microAppInfo:{
                appId:"ttef9b992670b151ec",
                appTitle:"小程序title",
                appUrl:"pages/movie/index?utm_source=share_wxapp&cityId=10&cityName=%E4%B8%8A%E6%B5%B7",
                description:"小程序描述"
            }, //可选,分享内容携带小程序
            extras:{
                "micro_app_task_id":"7265506428227xxxxxx",
                "agent_client_key":"xxxxxxxxxxxxxxxx"
            },//挂载小程序时必需要配置
            hashtags:[
                "话题"
            ],//可选, 分享内容携带话题//*/

            shareParam:{
                poiId: 'xxx', //poi 锚点数据,出现在发布页。
                musicParamObject: {
                    musicId: 'xxx',
                    start: 1
                },//背景音乐数据,可以设置图片或者视频的背景音乐
                titleObject: {
                    title: '分享标题',
                    shortTitle: '分享短标题',
                    hashtagTitleMarker: [
                        {
                            name: '直接插入标题中hashtag',
                            start: 2
                        }
                    ],
                    mentionTitleMarker: [
                        {
                            openId: 'xxx', //@用户对应的openid
                            start: 3
                        }
                    ]
                }, //标题,总长度有限制,过长会被截断
                stickersObject: {
                    hashtagSticker:[
                        {
                            name: 'xxx'
                        }
                    ], //>话题贴纸
                    customSticker:[
                        {
                            path: "xx", //文件路径 (传平台绝对路径,转换使用plus.io.convertLocalFileSystemURL())
                            startTime: 0,
                            endTime: 1000 * 1000,
                            normalizedSizeX: 0.5,  //归一化大小,宽除以屏幕宽
                            normalizedSizeY: 0.5, //归一化大小,高各除以屏幕高
                            scale: 1, //缩放
                            rotate: 0, //旋转
                            offsetX: 0.5,  //横纵向偏移,贴纸中心点在归一化屏幕中的位置
                            offsetY: 0.5  //横纵向偏移,贴纸中心点在归一化屏幕中的位置
                        }
                    ], //>自定义图片贴纸
                    mentionSticker:[
                        {
                            openId: "xxx"//@用户的openid,用户授权后可以获取到
                        }
                    ], //>@用户贴纸
                    poiSticker:[
                        {
                            poiId: "xxx" //poiId
                        }
                    ], //>Poi贴纸
                }, //贴纸
                dailyScale: 0.58, //日常内容缩放尺度
                shareDailyBGBaseColor: '#ff200d', //日常背景的基准色
                shareDailyBGComplementaryColor: '#ff200d', //日常背景的渐变色
                shareDailyBGUrl: '', //设置日常的背景图片
                privateStatus: 'Public', //视频发布后公开范围。可取值有:Public 所有人可见(公开)Private 仅自己可见(私密)Friends  朋友可见
                downloadType: 'AllowDownload', //视频发布后是否允许下载。可取值有:AllowDownload 允许下载  DenyDownload不允许下载
                shareDailyH5Path: 'http://xxx', //H5链接,需要在开平aweme.share scope下配置
            } //可选,新版分享携带参数
        },
        callback: function(response) {
            console.log("onShare:", response);
        }
    });
},

4、抖音分享到联系人

shareToContacts() {
    //分享图片
    this.shareToContacts1()

    //分享链接
    // this.shareToContacts2()

    //传imagePaths
    // this.shareToContacts3()
},

shareToContacts1() {
    //分享图片(相册选择)(Android使用uniapp自带选择,iOS有内置的)
    var that = this
    if (uni.getSystemInfoSync().platform == 'android') {
        uni.chooseImage({
            count: 1,
            sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
            sourceType: ['album'], //从相册选择
            success: function(res) {
                var paths = [];
                for (var i = 0; i < res.tempFilePaths.length; i++) {
                    var url = res.tempFilePaths[i];
                    paths[i] = plus.io.convertLocalFileSystemURL(url);
                }
                that.shareToContactsWithMediaIds(paths)
            }
        });
    } else {
        // sdkShortvideo.onShareContentToIM({
        //  isChooseImage: true, //打开相册选择图片视频等(只支持iOS)
        //  state: ""
        // }, function(res) {
        //  console.log(res);
        //  //res.errorCode     //参照官方文档说明
        //  //res.subErrorCode  //参考官方文档说明
        //  //res.errorMsg
        //  //res.state
        // });
    }
},
shareToContacts2() {
    //分享链接
    onShareContentToIM({
        params: {
            urlObject: {
                url: "https://open.douyin.com/platform", // 链接(必填)
                title: "抖音开放平台", //title(必填)
                discription: "抖音开放平台,致力于打造抖音开放的生态系统", //描述(必填)
                coverUrl: "https://sf3-cdn-tos.douyinstatic.com/obj/ttfe/open/imgs/logo-text.png" //封面图(远程图片)(必填)    
            },
            state: ""
        },
        callback: function(response) {
            console.log("onShareContentToIM:", response);
        }
    });
},
shareToContacts3() {
    //分享图片(传imagePaths)
    var that = this
    uni.downloadFile({
        url: 'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-f184e7c3-1912-41b2-b81f-435d1b37c7b4/5a7f902b-21a7-4822-884f-925219eacc4b.png',
        success: (res) => {
            if (res.statusCode === 200) {
                console.log('下载成功:', res);
                console.log("转换成平台绝对路径:" + plus.io.convertLocalFileSystemURL(res.tempFilePath))
                if (res.tempFilePath) {

                    if (uni.getSystemInfoSync().platform == 'android') {
                        that.shareToContactsWithMediaIds([plus.io.convertLocalFileSystemURL(res
                            .tempFilePath)])
                    } else {
                        //保存图片到手机相册(苹果需要保存到手机相册获取localIdentifier才行)
                        // sdkShortvideo.onSaveImageToPhotosAlbum({
                        //  filePath: plus.io.convertLocalFileSystemURL(res.tempFilePath),
                        //  type: 'image' //默认image,可选参数:image 或 video
                        // }, function(res2) {
                        //  if (res2.path) {
                        //      that.shareToContactsWithMediaIds([res2.path])
                        //  }
                        // });
                    }

                }
            }
        }
    });

},
shareToContactsWithMediaIds(media) {
    //>分享到抖音朋友(传imagePaths)
    onShareContentToIM({
        params: {
            // isChooseImage: true, //打开相册选择图片视频等(只支持iOS)
            imagePaths: media, //单图
            /*urlObject: { //链接
                url: "https://open.douyin.com/platform", // 链接(必填)
                title: "抖音开放平台", //title(必填)
                discription: "抖音开放平台,致力于打造抖音开放的生态系统", //描述(必填)
                coverUrl: "https://sf3-cdn-tos.douyinstatic.com/obj/ttfe/open/imgs/logo-text.png" //封面图(远程图片)(必填)    
            }, ///imagePaths和urlObject二选其一*/
            state: ""
        },
        callback: function(response) {
            console.log("onShareContentToIM:", response);
        }
    });
}

5、抖音打开拍摄器

openCapture() {
    //打开拍摄器
    onOpenCapture({
        params: {

            microAppInfo:{
                appId:"ttef9b992670b151ec",
                appTitle:"小程序title",
                appUrl:"pages/movie/index?utm_source=share_wxapp&cityId=10&cityName=%E4%B8%8A%E6%B5%B7",
                description:"小程序描述"
            }, //可选,分享内容携带小程序
            extras:{
                "micro_app_task_id":"7265506428227xxxxxx",
                "agent_client_key":"xxxxxxxxxxxxxxxx"
            },//挂载小程序时必需要配置
            hashtags:[
                "话题"
            ],//可选, 分享内容携带话题///*,*/
            state: "",

            shareParam:{
                poiId: 'xxx', //poi 锚点数据,出现在发布页。
                titleObject: {
                    title: '分享标题',
                    shortTitle: '分享短标题',
                    hashtagTitleMarker: [
                        {
                            name: '直接插入标题中hashtag',
                            start: 2
                        }
                    ],
                    mentionTitleMarker: [
                        {
                            openId: 'xxx', //@用户对应的openid
                            start: 3
                        }
                    ]
                }, //标题,总长度有限制,过长会被截断

            } //可选,携带额外参数

        },
        callback: function(response) {
            console.log("onOpenCapture:", response);
        }
    });
}

隐私、权限声明

1. 本插件需要申请的系统权限列表:

安卓:android.permission.INTERNET、android.permission.READ_EXTERNAL_STORAGE; 抖音SDK详情参照文档https://developer.open-douyin.com/docs/resource/zh-CN/dop/develop/sdk/mobile-app/sdk

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件不采集任何数据

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问