小程序调用wx.shareToOfficialAccount,报错;fail can only be invoked by user TAP gesture,
其它小程序能正常调用,是不是小程序还需要做设置之类的,wxba6543bb3afada5c则报错
数据是正常,方法如下
async onShareOffcialAccount() {
const imgurls = this.data.selectedImages.filter(item => item.selected)
const tempPaths = await fileManager.downloadImages(imgurls.map(item => item.url),{saveToAlbum:false});
const that = this
if (stringIsEmpty(this.data.content) || stringIsEmpty(this.data.title) || stringIsEmpty(officialPath)) {
that.showTip('题目、正文、话题须填写!')
return
}
// 文档 https://blog.minapper.com/12312.html
wx.shareToOfficialAccount({
title: this.data.title,
content: this.data.content,
tags: this.data.selectedTags,
path: officialPath,
images: tempPaths,
success: (res) => {
that.showTip('公众号文章发布成功')
},
fail: (err) => {
// 用户主动退出图文编辑器时触发
console.log(err)
},
complete: (res) => {
// 统计接口总共调用次数
console.log(res)
},
})
},

具体如下:
<button bindtap="onShareOffcialAccount">去发布公众号<button>
onShareOffcialAccount() {const imgurls = this.data.selectedImages.filter(item => item.selected)fileManager.downloadImages(imgurls.map(item => item.url), {saveToAlbum: false}).then(res=>{const { results }=resconst tempPaths = results.map(item => item.tempFilePath)console.log(tempPaths)const that = thisif (!tempPaths||stringIsEmpty(this.data.content) || stringIsEmpty(this.data.title) || stringIsEmpty(officialPath)) {that.showTip('题目、正文、话题须填写!')return}wx.shareToOfficialAccount({title: this.data.title,content: this.data.content,tags: this.data.selectedTags,path: officialPath,images: tempPaths,success: (res) => {that.showTip('公众号文章发布成功')},fail: (err) => {// 用户主动退出图文编辑器时触发console.log(err)},complete: (res) => {// 统计接口总共调用次数console.log(res)},})})},这个报错的意思是,该方法仅能通过用户点击触发。
必须用户点击,而且不能在异步回调里