HubMong
(HubMong)
December 23, 2021, 12:22pm
#1
Hello fellow bro developers!
Now I want to get data of Dow Jones Index for the last 30 days into Roblox Studio.
I use the external API and wrote the code as follows:
Blockquote
local HttpService = game:GetService(“HttpService”)
local ticker = ‘DJI’
local interval = ‘1day’
local outputsize = 30
local api_url = “https://api.twelvedata.com/time_series?symbol={"..ticker.."}&interval={"..interval.."}&outputsize={"..outputsize.."}&apikey={api_key} ”
local response = HttpService:GetAsync(api_url)
local data = HttpService:JSONDecode(response)
local mainBoard = script.Parent
local textLabel = mainBoard.SurfaceGui.Frame.TextLabel
local dji = game.Workspace.DJI
local part = dji.Part
local dateLabel = dji.Part.SurfaceGui.Frame.DateLabel
dateLabel.Text = os.date("%Y-%m-%d", os.time(os.date(’*t’)) - 86400)
print(data.values[1].datetime)
Blockquote
As you can see, “attempt to index nil with number” is displayed,
but I don’t know what is wrong.
I will appreciate if someone help me.
Mystxry12
(Mystxry)
December 23, 2021, 12:37pm
#2
Insert ur code inside ``` to format it.
local HttpService = game:GetService(“HttpService”)
local ticker = ‘DJI’
local interval = ‘1day’
local outputsize = 30
local api_url = “https://api.twelvedata.com/time_series?symbol={"..ticker.."}&interval={"..interval.."}&outputsize={"..outputsize.."}&apikey={api_key}”
local response = HttpService:GetAsync(api_url)
local data = HttpService:JSONDecode(response)
local mainBoard = script.Parent
local textLabel = mainBoard.SurfaceGui.Frame.TextLabel
local dji = game.Workspace.DJI
local part = dji.Part
local dateLabel = dji.Part.SurfaceGui.Frame.DateLabel
dateLabel.Text = os.date("%Y-%m-%d", os.time(os.date(’*t’)) - 86400)
print(data.values[1].datetime)
1 Like
HubMong
(HubMong)
December 23, 2021, 12:49pm
#3
Thank you for your reply
Blockquote
local HttpService = game:GetService(“HttpService”)
local ticker = ‘DJI’
local interval = ‘1day’
local outputsize = 30
local api_url = “https://api.twelvedata.com/time_series?symbol={"..ticker.."}&interval={"..interval.."}&outputsize={"..outputsize.."}&apikey={api_key} ”
local response = HttpService:GetAsync(api_url)
local data = HttpService:JSONDecode(response)
print(data.values[1].datetime)
Blockquote
Mystxry12
(Mystxry)
December 23, 2021, 12:51pm
#4
Btw cud u print data
and show us the output.
@HubMong
HubMong
(HubMong)
December 23, 2021, 12:55pm
#5
This is the screen when I used a python editor, where you can see the data is imported properly.
I noticed that in the screen shot a param in the url “api_key” seems to not have an api key, is that perhaps the problem? Or did you remove it (which makes sense)
1 Like
HubMong
(HubMong)
December 23, 2021, 12:58pm
#7
This is the error message in Studio when I use print method.
Mystxry12
(Mystxry)
December 23, 2021, 1:03pm
#8
Just try to print data. blah blahchar limit
1 Like
HubMong
(HubMong)
December 23, 2021, 1:06pm
#9
Yes, thank you for your advice. I changed the code as follows, but got the same error.
Try printing just data then, maybe we can see the problem
1 Like
HubMong
(HubMong)
December 23, 2021, 1:09pm
#11
Thank you for your smart advice. I tried and the result is as follows:
Now try printing data[1] like you did before
1 Like
Mystxry12
(Mystxry)
December 23, 2021, 1:12pm
#13
Try this:
print(data.values[0].datetime)
Update me with the result
1 Like
could you try
print(response)
to see the structure of the response
1 Like
HubMong
(HubMong)
December 23, 2021, 1:20pm
#17
I got the message as follows:
well, that means that there is an error with your request, not roblox…
Mystxry12
(Mystxry)
December 23, 2021, 1:24pm
#19
local url = string.format("https://api.twelvedata.com/time_series?symbol=%s&interval=%s&outputsize=%d&apikey=%s", ticker, interval, outputsize, api_key)
Ur url was completely wrong. Replace ur url with the above one. I had to look up the api, so pretty sure the above one works.
Pls update me if the above works @HubMong .
1 Like
HubMong
(HubMong)
December 23, 2021, 1:30pm
#20
Now I confirmed it work perfectly.
Thank you for your kind supports, guys!
2 Likes