bzarras / newsapi Goto Github PK
View Code? Open in Web Editor NEWA promise-based node interface for NewsAPI
License: MIT License
A promise-based node interface for NewsAPI
License: MIT License
Seems like NewsAPI itself is not returning titles or news content data at the moment.
Example response:
{
"status": "ok",
"totalResults": 35,
"articles": [
{
"author": null,
"source": {
"Id": null,
"Name": "Telegraph.co.uk"
},
"publishedAt": "2022-07-22T06:22:00Z",
"url": "https://www.telegraph.co.uk/athletics/2022/07/22/dina-asher-smith-claims-bronze-race-among-best-have-ever-seen/"
},
{...}
So I've made around 10 requests to this api using a developer account and I already got this error and asking me to upgrade my plan to make more requests lol
UnhandledPromiseRejectionWarning: NewsAPIError: parameterInvalid: You are trying to request results too far in the past. Your plan permits you to request articles as far back as 2019-07-07, but you have requested 2019-07-01. To extend this please upgrade to a paid plan.
Are there plans for typescript support?
Well I'm using newsapi to build a news application but in your ./dist/index.js
there's a function createUrlFromEndpointAndOptions
causing some problem that prevent it to run in browser.
var query = qs.stringify(options);
This line causing the problem.
Things I conclude from this :
querystring
library is completely built for node or we can say that it's for server only.newsapi
in client side we have to implement some other method to get the desire result.Thank You!!
I'm wondering if it is possible to filter news articles by a keyword. For example to filter by "climate change".
As far as I know you can only filter by the source of the press.
const NewsAPI = require('newsapi');
const newsapi = new NewsAPI(MY_API_KEY)
my console tells me "No API key specified" yet the API key is there, i later copied the API key from the .env file, place it, and still got the same error
1:17:24 AM react.1 | Failed to compile.
1:17:24 AM react.1 | ./node_modules/newsapi/dist/index.js
1:17:24 AM react.1 | Module not found: Can't resolve 'core-js/modules/es6.array.index-of' in
'C:\Users\abc\xyz-app\node_modules\newsapi\dist'
1:17:24 AM react.1 | Error from chokidar (C:): Error: EBUSY: resource busy or locked, lstat 'C:\hiberfil.sys'
1:17:24 AM react.1 | Error from chokidar (C:): Error: EBUSY: resource busy or locked, lstat 'C:\pagefile.sys'
1:17:24 AM react.1 | Error from chokidar (C:): Error: EBUSY: resource busy or locked, lstat 'C:\swapfile.sys'
My file --->
import { NewsAPI } from 'newsapi'
const newsapi = new NewsAPI('api key string goes here');
//const NewsAPI = require('newsapi'); **Tried both commonJS and ES6 imports...same error**
function getNews(){
newsapi.v2.everything({
q: 'bitcoin',
sources: 'bbc-news,the-verge',
domains: 'bbc.co.uk, techcrunch.com',
from: '2017-12-01',
to: '2017-12-12',
language: 'en',
sortBy: 'relevancy',
page: 2
}).then(response => {
console.log(response);
/*
{
status: "ok",
articles: [...]
}
*/
});
}
I can't seem to figure this out...I feel incredibly dumb guys but I am so excited to use this library...if anyone could provide any sort of direction I would be so grateful!!! Thank you so much.
The following error frequently occurs on npm compilations (runnning npm start with a React app):
./node_modules/newsapi/dist/index.js
Module not found: Can't resolve 'core-js/modules/es6.array.index-of' in '/my-app/node_modules/newsapi/dist'
When attempting to output a production build, the package is unable to minify. I got around this by manually creating an ES5 version, but I wanted to put it out there for anybody else that may run into the issue.
I have started a new express project I tested on the live server it worked then the first package I installed was news API package and I added API Key. it worked in localhost but when I put in the live server issue started.
The error is given below:
at require (internal/module.js:12:17)
at Object. (/var/www/html/demo/routes/index.js:4:17)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
SyntaxError: Unexpected token ...
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object. (/var/www/html/demo/routes/index.js:4:17)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
const response = await newsapi.v2.topHeadlines({
q: 'bitcoin',
language: 'en',
country: any country...
}
Returns results in all languages. Is it still possible to filter results to english only?
I installed the newsapi npm package to us in my node. It works perfectly in my localhost but when I hover on the
const newsAPI = require("newsapi
,
it says :
module "c:/Users/Godson/OneDrive/Documents/GitHub/blog/node_modules/newsapi/dist/index" Could not find a declaration file for module 'newsapi'. 'c:/Users/Godson/OneDrive/Documents/GitHub/blog/node_modules/newsapi/dist/index.js' implicitly has an 'any' type. Try npm i --save-dev @types/newsapi if it exists or add a new declaration (.d.ts) file containing declare module 'newsapi';
and this affects my repo when I deploy to render, it also says
Error: Cannot find module "newsapi
.
My node version is v16.15.1
I notice I can't fetch some data by my code from News API anymore, so I search on News API website.
So now they don't alow us to fetch description and urlToImage anymore?
I'm using the developer plan, is it possible to fetch those data by upgrade to business plan?
This is my fetch url:
https://newsapi.org/v2/top-headlines?country=us&category=general&pageSize=100&apiKey=[My api key]
Tried to get news with the following example from official website
const NewsAPI = require('newsapi');
const newsapi = new NewsAPI('7bfd3e755d524648883ebae00d2280f7');
newsapi.v2.topHeadlines({
sources: 'bbc-news,the-verge',
q: 'bitcoin',
category: 'business',
language: 'en',
country: 'us'
}).then(response => {
console.log(response);
/*
{
status: "ok",
articles: [...]
}
*/
});
but keep getting error 'You cannot mix the sources parameter with the country or category parameters'. When I remove sources I don't get any articles back.
node version 9.11.
running on local express server
Is this module compatible with React Native? When I try to use it I get several errors about modules such as querystring and crypto missing, which appear to be dependencies of this module and are normally installed automatically by npm.
error: bundling failed: Error: Unable to resolve module querystring from /node_modules/newsapi/index.js: Module does not exist in the module map
If I manually install them I eventually get stuck as well.
npm WARN saveError ENOENT: no such file or directory, open '...\project\package.json' npm notice created a lockfile as package-lock.json. You should commit this file. npm WARN enoent ENOENT: no such file or directory, open '...\project\package.json' npm WARN project No description npm WARN project No README data npm WARN project No license field.
It seems to me as though all the right files exist in node_modules/newsapi (node-modules/newsapi/package.json is created) but ultimately I can tell that there is a problem because the following line const NewsAPI = require('newsapi');
throws me this warning about the declaration file: "Could not find a declaration file for module 'newsapi'. '.../project/node_modules/newsapi/dist/index.js' implicitly has an 'any' type.
Try npm install @types/newsapi
if it exists or add a new declaration (.d.ts) file containing declare module 'newsapi';
ts(7016)"
Access to fetch at 'https://newsapi.org/v2/top-headlines?country=in&category=general&sources=&q=&pageSize=20&page=1' from origin 'http://192.168.0.5:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
I had seen CORS error also on the link where I've deployed my app. Could you let me know how to solve this?
Hi,
I noticed the API always cuts off content data, leaving something like this at the end of the string [+2219 chars]
Is there any way to tell the API to give the full content and not shorten it?
Hello @bzarras . I am facing an issue.
I am using the nodejs client with discord.js. However it doesn't depend on the module discord.js. What I am trying to ask is why does it gimme the error Cannot read property 'everything' of undefined
???
Hope you will help.
I am Calling your api for news app.
I need to show News Categories and it's articles
so when using your code I found this Error:
(node:3148) UnhandledPromiseRejectionWarning: NewsAPIError: parametersIncompatible: You cannot mix the sources parameter with the country or category parameters. atD:\Full\BackEnd\node_modules\newsapi\dist\index.js:272:40 at <anonymous> at process._tickCallback (internal/process/next_tick.js:189:7) (node:3148) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:3148) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Any Help !!
https://newsapi.org/docs/caching
Please consider adding support for disabling caching.
When testing api from localhost, it gives me this error. I tried everything. To duplicate you can just try to call any api any way you want and it will give this error..
Testing on Node.js
Access to fetch at 'https://newsapi.org/v2/everything?q=bitcoin&sources=bbc-news%2Cthe-verge&domains=bbc.co.uk%2C%20techcrunch.com&language=en&sortBy=relevancy&page=2' from origin 'http://localhost:8080' has been blocked by CORS policy: Request header field access-control-allow-origin is not allowed by Access-Control-Allow-Headers in preflight response.
The key doesn't seem to work on my server:
I have validated the key is being logged properly right before usage.
NewsAPIError: apiKeyInvalid: Your API key is invalid or incorrect. Check your key, or go to https://newsapi.org to create a free API key.
It works fine locally.
Will this be updated to use the new V2 version of the NewsAPI? (Based on https://newsapi.org/docs/v2-migration)
The example on the newsapi site for this library is broken. It is listed as:
newsapi.v2.topHeadlines({
sources: 'bbc-news,the-verge',
q: 'bitcoin',
category: 'business',
language: 'en',
country: 'us'
}).then(response => {
console.log(response);
/*
{
status: "ok",
articles: [...]
}
*/
});
returns
NewsAPIError: parametersIncompatible: You cannot mix the sources parameter with the country or category parameters.
Just a heads up, may want to have that fixed
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.