Giter Site home page Giter Site logo

newsapi's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

newsapi's Issues

Upstream issue with NewsAPI

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/"
        },
{...}

Unhandled promise rejections

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.

"querystring" has been externalized for browser compatibility. Cannot access "querystring.stringify" in client code.

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 :

  1. querystring library is completely built for node or we can say that it's for server only.
  2. In order to run the newsapi in client side we have to implement some other method to get the desire result.

Thank You!!

Filtering by keyword

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.

No API key specified

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

Can't resolve 'core-js/modules/es6.array.index-of'

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.

core-js compilation error

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'

npm package not working in live server

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)

Language filter not working in node.js

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?

Could not find a declarative file for module "newsapi"

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

NewsAPIError: parametersIncompatible

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

React Native

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.

When I run 'npm install newsapi --save' core-js and node-fetch install properly, but I get the following warnings regarding newsapi:

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)"

CORS problem

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?

API cuts off content data

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?

Suggestions for newsapi

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.

Api Node Version Error

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 !!

Problem with CORS policy, when making a request to https://newsapi.org

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.

code works locally but not in production

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.

Example on https://newsapi.org/docs/client-libraries/node-js throws an error

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.