Cannot read property 'expires_in' of undefined
来源:2-6 第二天 票据 access_token 打开新世界大门

惘玮
2017-08-14
request().then(function(response){}),回调函数返回的是对象而不是数组,这是什么问题。
console.log(response instanceof Array) //false
写回答
2回答
-
人间能得几回闻
2017-10-11
把 response[1] 这个[1] 去掉就好了, 我用get方法到浏览器请求了下,发现返回的data 就是access_token和expires_in。 所以下面data.expires_in 肯定没有 expires_in这个属性了,相当用expires_in.expires_in
Wechat.prototype.updateAccessToken = function () { var appID = this.appID var appSecret = this.appSecret var url = api.accessToken + '&appid=' + appID + '&secret=' + appSecret return new Promise(function (resolve,reject) { request({url:url,json:true}).then(function (response) { var data = response var now = (new Date().getTime()) var expires_in = now + (data.expires_in - 20) * 1000 data.expires_in = expires_in resolve(data) }) }) }
}
00 -
Scott
2017-08-19
request 的版本不同导致,这里的你通过 response.body 来获取数据试试看
00
相似问题