That should work however GetAsync only returns the body and the solution to this error should be in the headers. Try running this and tell me the results
Well looking at the response it gave you, its nothing to do with how the the news API itself (so nothing has changed on their end). But instead it looks like it might possibly be the formatting of your request, as it goes to the first endpoint and realises that your formatting is off for what it supports and it simply says ânoâ and responds back saying I donât like your formatting.
Can we see the request you make (hiding your API key)?
{âstatusâ:âerrorâ,âcodeâ:âapiKeyInvalidâ,âmessageâ:âYour API key is invalid or incorrect. Check your key, or go to https://newsapi.org to create a free API key.â}
The entire system works in 2 server scripts and one local script , but I will sent the crucial part.
local SearchRemote = game.ReplicatedStorage.Search
local UpdateClients = game.ReplicatedStorage.Update
local HideRemote = game.ReplicatedStorage.Hide
local ShowRemote = game.ReplicatedStorage.Show
function OnRequest(plr, input)
ShowRemote:FireAllClients()
print(plr.Name .. " requested.")
local http = game:GetService("HttpService")
local key = "i hided the key! but it is 100% correct on my client."
local search = input
local request = ("https://newsapi.org/v2/everything?q=" .. search .. "&apiKey=" .. key .."&from=2020-11-10&sortBy=published")
local response = http:RequestAsync(
{
Url = request,
Method = "GET"
}
)
local result = http:JSONDecode(response)
UpdateClients:FireAllClients(
"Search Query",
result.articles[1].title,
result.articles[1].url,
result.articles[1].description,
result.articles[2].title,
result.articles[2].url,
result.articles[2].description,
result.articles[3].title,
result.articles[3].url,
result.articles[3].description,
result.articles[4].title,
result.articles[4].url,
result.articles[4].description,
result.articles[5].title,
result.articles[5].url,
result.articles[5].description
)
clr() -- This will happen 20 sec after results were sent.
end
function clr()
wait(20)
HideRemote:FireAllClients()
end
SearchRemote.OnServerEvent:Connect(OnRequest)
That might be the reason why it flagged but it will eliminate the problem.
The more likely issue:
However according to the API documentation you donât need to set the method so the second cause of your issue might be that you need to do response as follows instead of how youâve done it:
This is most likely a Roblox or newsapi issue. The issue is that newsapi requires a protocol that Roblox does not support. According to this post Does Roblox support http/2 protocol? - #8 by Corecii Roblox only supports HTTP 1.1 and according to keycdnâs HTTP 2 test newsapi only supports HTTP 2.
Normally an "upgrade" header would be sent which would mention the expected protocol according to MDN but Roblox probably doesnât return it. Unless there is a way to change the supported protocols on newsapi, you would have to use a proxy server that upgrades Robloxâs requestâs to the protocol newsapi supports, or you could make a feature request to add HTTP 2 support.