errcode: 40007,invalid media_id
来源:4-7 第四天 荡平永久素材接口-查询永久素材数量接口、获取永久素材列表接口
慕粉3278383
2016-05-13
获取素材是为什么 会
errcode: 40007,
errmsg: 'invalid media_id hint: [qzexua0596ure1]'
{ xml:
{ ToUserName: [ 'gh_a1fa4a51afca' ],
FromUserName: [ 'omt_gw-lQqAVp4-o1p_lQmxD0vC0' ],
CreateTime: [ '1463148594' ],
MsgType: [ 'text' ],
Content: [ '10' ],
MsgId: [ '6284175360828689257' ] } }
{ ToUserName: 'gh_a1fa4a51afca',
FromUserName: 'omt_gw-lQqAVp4-o1p_lQmxD0vC0',
CreateTime: '1463148594',
MsgType: 'text',
Content: '10',
MsgId: '6284175360828689257' }
https://api.weixin.qq.com/cgi-bin/material/add_material?&access_token=uxXEjVNDKQ
Le-snkIIqyX-OL-cJFzGnAj-Y8vZbzxxKuUfpp9viuasIiY2Fb-Fax5j7tAtrIFdBRLd6vtoqR889m91
5tPoiVpjPKXxTO3fquJ21OhUi6jlHqlLr4NY8QGSDeAJAKWH
https://api.weixin.qq.com/cgi-bin/material/add_news?&access_token=uxXEjVNDKQLe-s
nkIIqyX-OL-cJFzGnAj-Y8vZbzxxKuUfpp9viuasIiY2Fb-Fax5j7tAtrIFdBRLd6vtoqR889m915tPo
iVpjPKXxTO3fquJ21OhUi6jlHqlLr4NY8QGSDeAJAKWH
{ errcode: 40007,
errmsg: 'invalid media_id hint: [qzexua0596ure1]' }
TypeError: Cannot read property 'forEach' of undefined
at Object.exports.reply (C:\Users\liuhui\Desktop\wechat\weixin.js:160:9)
at next (native)
at onFulfilled (C:\Users\liuhui\Desktop\wechat\node_modules\co\index.js:65
:19)
at tryCatcher (C:\Users\liuhui\Desktop\wechat\node_modules\bluebird\js\rel
ease\util.js:16:23)
at Promise._settlePromiseFromHandler (C:\Users\liuhui\Desktop\wechat\node_
modules\bluebird\js\release\promise.js:502:31)
at Promise._settlePromise (C:\Users\liuhui\Desktop\wechat\node_modules\blu
ebird\js\release\promise.js:559:18)
at Promise._settlePromise0 (C:\Users\liuhui\Desktop\wechat\node_modules\bl
uebird\js\release\promise.js:604:10)
at Promise._settlePromises (C:\Users\liuhui\Desktop\wechat\node_modules\bl
uebird\js\release\promise.js:683:18)
at Async._drainQueue (C:\Users\liuhui\Desktop\wechat\node_modules\bluebird
\js\release\async.js:138:16)
at Async._drainQueues (C:\Users\liuhui\Desktop\wechat\node_modules\bluebir
d\js\release\async.js:148:10)
at Immediate.Async.drainQueues [as _onImmediate] (C:\Users\liuhui\Desktop\
wechat\node_modules\bluebird\js\release\async.js:17:14)
at tryOnImmediate (timers.js:543:15)
at processImmediate [as _immediateCallback] (timers.js:523:5)
Wechat.prototype.fetchMaterial = function(mediaId, type, permanent) {
var that = this
var fetchUrl = api.temporary.fetch
if(permanent) {
fetchUrl = api.permanent.fetch
}
return new Promise(function(resolve, reject){
that.fetchAccessToken()
.then(function(data) {
var url = fetchUrl + '&access_token=' + data.access_token
var form = {}
var options = {method: 'POST', url: url, json: true}
if(permanent) {
form.media_id = mediaId
form.access_token = data.access_token
options.body = form
}
else {
if (type === 'video') {
url = url.replace('https://', 'http://')
}
url += '&media_id=' + mediaId
}
if (type === 'news' || type === 'video') {
request(options).then(function(response) {
var _data = response.body
if(_data) {
resolve(_data);
//console.log(_data)
}
else {
throw new Error('Fetch material fails')
}
})
.catch(function(err) {
reject(err)
})
}
else {
resolve(url) //返回url
}
})
})
}else if (content === '10') {
var picData = yield wechatApi.uploadMaterial('image', path.join(__dirname, '/mei.jpg'),{})
var media = {
articles: [{
title: 'cool',
thumb_media_id: picData.media_id,
author: 'lh',
digest: '没有摘要',
show_cover_pic: 1,
content: '没有内容',
content_source_url: 'http://github.com'
},{
title: 'cool2',
thumb_media_id: picData.media_id,
author: 'lh',
digest: '没有摘要',
show_cover_pic: 1,
content: '没有内容',
content_source_url: 'http://github.com'
}]
}
data = yield wechatApi.uploadMaterial('news', media, {}) //上传永久素材图文
data = yield wechatApi.fetchMaterial(data.meida_id, 'news', {}) //拿到详细信息
console.log(data)
var items = data.news_item
var news = []
items.forEach(function(item) { //把多图文拼成回复的数组
news.push({
title: item.title,
decription: item.digest,
picUrl: picData.url,
url: item.url
})
})
reply = news
}1回答
-
Scott
2016-05-14
data = yield wechatApi.uploadMaterial('news', media, {}) //上传永久素材图文
data = yield wechatApi.fetchMaterial(data.meida_id, 'news', {}) //拿到详细信息
console.log(data)
这里的 media_id 拼错拼成了 meida_id 了吧
00
相似问题