Open themox opened 2 years ago
Looks like NewsAPI changed their requirements in the last few days. Some troubleshooting with toy code based on the nodehelper.js from this module yielded the following error:
{"status":"error","code":"userAgentMissing","message":"Please set your User-Agent header to identify your application. Anonymous requests are not allowed."}
So I modified the code in nodehelper.js like below to add a User-Agent string to the header of the request, which works. Almost doesn't matter what you put in there as long as it is non-null. Recommend a change like below. If I get time later I'll make a pull request for the fix. Probably do something like a configurable UserAgent in the config, with a default being MagicMirror or something like that.
/* Magic Mirror
* Module: MMM-EveryNews
*
* By Mykle1
*
*/
const NodeHelper = require('node_helper');
const request = require('request');
module.exports = NodeHelper.create({
start: function() {
console.log("Starting node_helper for: " + this.name);
},
getNatGeo: function(url) {
request({
url: 'https://newsapi.org/v2/top-headlines?sources='+this.config.source+'&pageSize=50&sortBy=popularity&apiKey='+this.config.apiKey,
headers: {'User-Agent':'MagicMirror'},
method: 'GET'
}, (error, response, body) => {
if (!error && response.statusCode == 200) {
var result = JSON.parse(body).articles;
this.sendSocketNotification('NATGEO_RESULT', result);
}
});
},
socketNotificationReceived: function(notification, payload) {
if (notification === 'GET_NATGEO') {
this.getNatGeo(payload);
}
if (notification === 'CONFIG') {
this.config = payload;
// console.log(this.config);
}
}
});
This is fixed by pull request #6 . Recommend close upon merge of that with main branch. @mykle1
I had the same issue the pull fixed it, @mykle1 I don't know you but I'm a big fan of your modules. Thank you for all your work! -Fellow NYorker
Hi, this module is no longer working for me. It stopped a couple days ago pulling down requests. It looks like it is making a request but never processing a response. I have tried uninstalling it and reinstalling it and no luck. When I did do that, I get the following error and MM was crashing on load.
So I did some googling and tried to install the missing module (request):
MM now loads normally but EveryNews never gets past the loading message.