project_cryptoverse icon indicating copy to clipboard operation
project_cryptoverse copied to clipboard

bing news api not working

Open agnivachatterjee opened this issue 2 years ago • 6 comments

i am getting a bad request error and it is not fetching any data

agnivachatterjee avatar Oct 11 '21 02:10 agnivachatterjee

/search?q=${newsCategory}&safeSearch=Off&textFormat=Raw&freshness=Day&count=${count}

use this on cryptoNewsApi.js and keep the base the url const baseUrl = "https://bing-news-search1.p.rapidapi.com/news";

agnxsh avatar Nov 18 '21 11:11 agnxsh

My news section wouldn't work at all until I skipped ahead and used useState, it has been confusing.

aindriu80 avatar Nov 19 '21 16:11 aindriu80

I've skipped ahead to add useState, reconfigured my query to

/search?q=${newsCategory}&safeSearch=Off&textFormat=Raw&freshness=Day&count=${count}

and I'm still getting

GET https://bing-news-search1.p.rapidapi.com/news/search?q=[object%20Object]&safeSearch=Off&textFormat=Raw&freshness=Day&count=undefined 400 (Bad Request)

At least my error changed from 404 to a 400. I've been stuck on this for hours, any help would be greatly appreciated.

Darkskittlz avatar Dec 18 '21 15:12 Darkskittlz

GET https://bing-news-search1.p.rapidapi.com/news/search?q=[object%20Object]&safeSearch=Off&textFormat=Raw&freshness=Day&count=undefined 400 (Bad Request)

In the above request newsCategory is of type string, but I can see it has got transformed into something like object%20Object, and count is undefined.

My Opinion:

  • Check whether the parameters newsCategory and count which is passed has valid value.

someshkrish avatar Feb 02 '22 06:02 someshkrish

Here Check inside news.jsx I passed -> const {data:cryptoNews} = useGetCryptoNewsQuery({type:'CryptoCurrency',count:10})

and inside cryptoNewsApi query builder I did -> query: (category) => createRequest(/search?q=${category.type}&safeSearch=Off&textFormat=Raw&freshness=Day&count=${category.count});

Passed whole object with props from news.jsx and just fetched it inside Builder; Easy Peasy Problem Solved;

Hope it helps because its working in my project like this and i came across same problem too.

jatin711-debug avatar Feb 04 '22 05:02 jatin711-debug

Thank you both.

Darkskittlz avatar Feb 14 '22 05:02 Darkskittlz