Page 1 of 2

Using imgBB api in livecode (solved)

Posted: Thu Sep 24, 2020 8:18 pm
by BigameOver
Hi,
I tried to use the imgBB api in livecode, but it didn't worked well for me.
https://api.imgbb.com/
Do you know how can i use it in my program?
I have the basic free livecode edition if that matters
Thank you

Re: Using bbimg api in livecode

Posted: Thu Sep 24, 2020 8:37 pm
by FourthWorld
LC supports sockets, and provides a library using sockets for HTTP. You can start with the GET and POST commands in the Dictionary, and chime back in if there's anything in the API that's not clear on how to call it from LC.

Re: Using bbimg api in livecode

Posted: Fri Sep 25, 2020 5:58 pm
by BigameOver
Hi FourthWorld,
I tried to do this code but when i run it livecode crashes:

Code: Select all

on mouseUp
   put base64Encode(image "my_image") into _tImage
   request POST "https://api.imgbb.com/1/upload?key=YOUR_CLIENT_API_KEY?image=" & _tImage
end mouseUp
What can I do?
Thanks

Re: Using bbimg api in livecode

Posted: Fri Sep 25, 2020 6:29 pm
by Klaus
BigameOver wrote:
Fri Sep 25, 2020 5:58 pm
What can I do?
The dictionary is really helpful with these things! 8)
This should do:

Code: Select all

on mouseUp
   put base64Encode(image "my_image") into _tImage
   POST _timage to URL "https://api.imgbb.com/1/upload?key=YOUR_CLIENT_API_KEY?image="
end mouseUp
But LC should NEVER crash! :(

Re: Using bbimg api in livecode

Posted: Fri Sep 25, 2020 7:23 pm
by BigameOver
Hi Klaus,
Unfortunaly, It doesn't work for me :(
When I answer it it says ""status_code":400,"error":{"message":"Invalid API v1 key.","code":100,"context":"Exception"},"status_txt":"Bad Request"

Re: Using bbimg api in livecode

Posted: Sat Sep 26, 2020 8:14 am
by Klaus
If your api key is correct, what the error tries to tell you, try this:

Code: Select all

on mouseUp
   put "image=" & base64Encode(image "my_image") into _tImage
   POST _timage to URL "https://api.imgbb.com/1/upload?key=YOUR_CLIENT_API_KEY?"
end mouseUp

Re: Using bbimg api in livecode

Posted: Sat Sep 26, 2020 8:51 am
by BigameOver
Klaus wrote:
Sat Sep 26, 2020 8:14 am
If your api key is correct, what the error tries to tell you, try this:

Code: Select all

on mouseUp
   put "image=" & base64Encode(image "my_image") into _tImage
   POST _timage to URL "https://api.imgbb.com/1/upload?key=YOUR_CLIENT_API_KEY?"
end mouseUp
My api key is correct but now it says this:
{"status_code":400,"error":{"message":"Invalid base64 string.","code":120,"context":"Exception"},"status_txt":"Bad Request"}
How can I fix this?

Re: Using bbimg api in livecode

Posted: Sat Sep 26, 2020 12:03 pm
by Klaus
Sorry, out of ideas...

Re: Using bbimg api in livecode

Posted: Sat Sep 26, 2020 12:27 pm
by BigameOver
Does anybody else know?

Re: Using bbimg api in livecode

Posted: Sat Sep 26, 2020 7:54 pm
by FourthWorld
What headers are required by the API? And have you successfully authenticated?

Re: Using bbimg api in livecode

Posted: Sat Sep 26, 2020 8:02 pm
by BigameOver
FourthWorld wrote:
Sat Sep 26, 2020 7:54 pm
What headers are required by the API? And have you successfully authenticated?
The key and the image are required by the API. I got my key from the site and just copied it.

Re: Using bbimg api in livecode

Posted: Sat Sep 26, 2020 8:09 pm
by FourthWorld
Have you been able to use those successfully in Postman or other tool outside of LC?

Re: Using imgbb api in livecode

Posted: Sat Sep 26, 2020 8:24 pm
by BigameOver
FourthWorld wrote:
Sat Sep 26, 2020 8:09 pm
Have you been able to use those successfully in Postman or other tool outside of LC?
I haven't heard of postman as it is my first time trying to use an API in livecode but searching this on google with imgbb leading to zero result

Re: Using imgBB api in livecode

Posted: Sat Sep 26, 2020 8:59 pm
by FourthWorld
Postman is a very popular tool for testing HTTP-based APIs.
https://www.postman.com/

Re: Using imgBB api in livecode

Posted: Sat Sep 26, 2020 9:22 pm
by BigameOver
FourthWorld wrote:
Sat Sep 26, 2020 8:59 pm
Postman is a very popular tool for testing HTTP-based APIs.
https://www.postman.com/
Hi,
I tried to use the API in Postman with the example on the imgBB's site but it only says in the status: 404 Not Found
What I don't do right?