tt.shareAppMessage
收藏我的收藏
基础库 1.0.0 开始支持本方法,这是一个异步方法。
前提条件 | 无 |
业务背景 | 无 |
使用限制 | 无 |
注意事项 | 参数 options 是一个 ShareParam 对象分享图片取自「开发者后台-运营能力-必接能力-分享配置」的配置图片,若无该配置,平台将使用兜底图片替代生成的分享链接有效期为 45 天,过期后链接失效报错返回 'get shareInfo return null' 时为获取分享信息失败,可能为获取分享信息时网络请求超时,或者是当前 appID 的分享状态异常,比如被封禁导致,可以检查站内信或通过运营群进行反馈(接入指南 -联系我们) |
相关教程 |
语法
tt.shareAppMessage(options)
参数说明
options 为 object 类型,属性详见 ShareParam
回调成功
object 类型,属性如下:
属性名 | 类型 | 说明 | 最低支持版本 |
data | array | 仅当入参 options 中 channel='invite' 时返回,包含邀请对象的用户名和用户头像。(当邀请多个好友或群聊时,目前仅会返回一个好友的信息,群聊的信息暂不支持返回) | 2.54.0 |
data 类型说明
object 类型,属性如下:
属性名 | 类型 | 说明 | 最低支持版本 |
name | string | 分享对象的用户名 | 2.54.0 |
icon | string | 分享对象的用户头像 | 2.54.0 |
回调失败
object 类型,属性如下:
属性名 | 类型 | 说明 | 最低支持版本 |
errMsg | string | "shareAppMessage:fail" + 错误信息 | 1.0.0 |
错误码
errNo | errMsg | 说明 | 最低支持版本 |
21101 | permission denied,channel: %s | | 1.0.0 |
21102 | can not be shared without clicking by user | | 1.0.0 |
21103 | file not exist path:%s | | 1.0.0 |
21104 | file not readable path:%s | | 1.0.0 |
21105 | video file is too short path:%s | | 1.0.0 |
10200 | auth deny | | 1.0.0 |
21107 | stickerId and cutTemplateId are mutually exclusive | | 1.0.0 |
21108 | stickerId unavailable %s | | 1.0.0 |
21109 | cutTemplateId unavailable %s | | 1.0.0 |
21110 | use cut template fail | | 1.0.0 |
21111 | share permission denied | | 1.0.0 |
21112 | share image feature not support | | 1.0.0 |
10403 | onBusinessError unknown biz error | 1.0.0 | |
20001 | invalid param | 参数错误 | 1.0.0 |
10401 | Invalid CommonInfo. | 1.0.0 | |
10301 | feature is not supported in app | | 1.0.0 |
10401 | Internal error: show board error / Share error | 1.0.0 | |
10502 | cancel | | 1.0.0 |
20000 | not support channel:video | | 1.0.0 |
20000 | not support channel:picture | | 1.0.0 |
20001 | should not pass in useTmeaInvitationStyle and shareImagePath together | | 1.0.0 |
20001 | TaskGameId Not Found | | 1.0.0 |
10103 | network unavailable | | 1.0.0 |
代码示例
【示例一】使用审核通过的分享素材
tt.shareAppMessage({ templateId: "", // 替换成通过审核的分享ID query: "", success() { console.log("分享成功"); }, fail(e) { console.log("分享失败"); }, });
【示例二】邀请好友
tt.shareAppMessage({ channel: "invite", // 拉起邀请面板分享游戏好友 templateId: "", // 替换成通过审核的分享ID query: "", success(res) { console.log("分享成功" + JSON.stringify(res)); }, fail(e) { console.log("分享失败"); }, });
【示例三】组队分享
tt.shareAppMessage({ templateId: "", // 替换成通过审核的分享ID extra: { useTeamInvitationStyle: true, // 标识该消息为组队消息 activityID: "", // 从步骤一获取 templateInfo: [ { name: "memberCount", value: "1" }, { name: "roomLimit", value: "4" } ], versionType: "current" // 指定通过动态消息进入的小游戏版本:线上版current、测试版latest }, success() { console.log("分享成功"); }, fail(e) { console.log("分享失败"); }, });
【示例四】视频分享
// 视频分享 tt.shareAppMessage({ channel: "video", query: "", templateId: "1fidnqkeari9dnd18o", // 替换成通过审核的分享ID title: "画家活下去", desc: "在这里爱上画画", extra: { videoTopics: ["画家活下去"], }, success() { console.log("分享视频成功"); }, fail(e) { console.log("分享视频失败"); }, });
【示例五】录屏分享
// 视频分享 tt.shareAppMessage({ channel: "video", query: "", templateId: "1fidnqkeari9dnd18o", // 替换成通过审核的分享ID title: "画家活下去", desc: "在这里爱上画画", extra: { videoPath: "ttfile://temp/test.mp4", // 可用录屏得到的本地文件路径 videoTopics: ["画家活下去"], }, success() { console.log("分享视频成功"); }, fail(e) { console.log("分享视频失败"); }, });
