[ASK] Pars JSON from API Link with Autentication and Password

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

[ASK] Pars JSON from API Link with Autentication and Password

Post by gilar » Sat Mar 14, 2020 1:55 pm

Hello everybody ....

I'm strugling to Pars JSON from a API link
here is the link https://api.racehero.io/v1/events/3134/ ... board.json
This is the API documentation https://racehero.docs.apiary.io/#/authe ... irst%2F200


and this is my code

Code: Select all

   -- add the HTTP headers
   put "Content-Type: application/json" & CRLF into tHeaders
   put "Accept: application/json" & CRLF after tHeaders
   set the httpHeaders to tHeaders
   
   -- encode the params
   put urlEncode("dc43bb5fab5f86a11fb9") into tUsername
   put urlEncode("gilarkadarsah") into tPassword
   
   --send to Parse and get the results
   put "https://api.racehero.io/v1/events/3134/live/leaderboard.json?Username="&tUsername&"&Password="&tPassword into loginURL
   put URL loginURL into tResults
   put tResults into field "Field"
   put tResults into tArrays
   
   ParsingJSon tArrays

anyone could point me into right direction?
Comment and Help would be Appriciate


Best Regards

Gilar
Gilar | from INDONESIA

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: [ASK] Pars JSON from API Link with Autentication and Password

Post by bangkok » Sat Mar 14, 2020 5:25 pm

gilar wrote:
Sat Mar 14, 2020 1:55 pm
I'm strugling to Pars JSON from a API link
What are the problems you face ?

Regarding your code, you might have a problem with :

Code: Select all

  ParsingJSon tArrays
You have 2 solutions :

Code: Select all

   put JsonImport(tResults) into tArray --- that's LiveCode JSON library
or

Code: Select all

put JsonToArray(tResults) into tArray  --- that MergJSON library
I prefer MergJSON library... more stable in my views.

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: [ASK] Pars JSON from API Link with Autentication and Password

Post by gilar » Sat Mar 14, 2020 5:56 pm

My problem is login into API with Live code
how to put API key and Password in Livecode

I have done qith jaon
Gilar | from INDONESIA

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: [ASK] Pars JSON from API Link with Autentication and Password

Post by gilar » Sat Apr 25, 2020 11:36 am

Finally this solved with

Code: Select all

put "Authorization: Basic" && base64Encode("APIKEY:PASSWORD") into tHeader
   set the httpHeaders to tHeader
Hope it would be useful for somebody who has the same problem

Thanks
Gilar | from INDONESIA

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”