Page 1 of 1
http request problem
Posted: Sun Mar 01, 2020 1:48 am
by paulalsmith1000
Hi There
I've just come back to livecode after a while and something I'd already done doesn't seem to work?
I've formed htto requests before without any problems, but now this happens:-
GET url ("
https://www.googleapis.com/youtube/v3/s ... t&q=little simz, offence&key=AIzaSyC-k5IU6jr9eHxL7Zkt-QQEO4pPW4zdIp0") ; put it into theURL
-works fine, but if I try to add in variables
put "
https://www.googleapis.com/youtube/v3/s ... snippet&q=" & ttitle & ", " & tartist & "&key=AIzaSyDUT_zKdAsDjXNmUzyiGQU-9ooAewZ3qQE" into theURL
GET url(theURL) ; put it into theURL
-it doesn't work. could anyone suggest why?
kind regards
Paul
Re: http request problem
Posted: Sun Mar 01, 2020 2:20 am
by FourthWorld
1. Have you verified that ttitle and tartist contain what you expect? Does the resulting URL work in a browser?
2. Is that your actual app API key? If so you might want to change it now that it's been posted in a public forum.
Re: http request problem
Posted: Sun Mar 01, 2020 6:56 am
by bangkok
& ttitle
& ", "& tartist & "&key=AIzaSyDUT_zKdAsDjXNmUzyiGQU-9ooAewZ3qQE" into theURL
Watch out....
A space in a URL is a no go....
And it's clear to me that you have a space in your URL
(after the comma)
Re: http request problem
Posted: Sun Mar 01, 2020 11:45 am
by paulalsmith1000
Hi There
I have tested the resulting URL in the browser and it works fine (it returns the json response as expected), so the variables and the key work.
if I 'put' the result with the variable URL, I get this back????
Kind regards
Paul
<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 400 (Bad Request)!!1</title>
<style>
*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//
www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//
www.google.com/images/branding/googlelo ... 0x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//
www.google.com/images/branding/googlelo ... 0x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//
www.google.com/images/branding/googlelo ... 0x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//
www.google.com/images/branding/googlelo ... 0x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
</style>
<a href=//
www.google.com/><span id=logo aria-label=Google></span></a>
<p><b>400.</b> <ins>Thatâs an error.</ins>
<p>Your client has issued a malformed or illegal request. <ins>Thatâs all we know.</ins>
Re: http request problem
Posted: Sun Mar 01, 2020 12:16 pm
by bogs
bangkok wrote: ↑Sun Mar 01, 2020 6:56 am
A space in a URL is a no go....
paulalsmith1000 wrote: ↑Sun Mar 01, 2020 11:45 am
I have tested the resulting URL in the browser and it works fine
When you test the URL in a browser, the browser itself inserts a %20 to replace the 'space' in the address,
- I need less space...s...
- aPic_urlWithSpacesInBrowser.png (8.07 KiB) Viewed 4203 times
where as Lc does not, you'd have to insert those yourself through code if such are there, hence what bangkok is telling you.
Re: http request problem
Posted: Sun Mar 01, 2020 4:27 pm
by paulalsmith1000
Thank you very much for your help.
It turns out I was being a div anyway!
I'd removed the space before, because I thought it might be the problem, but it had no affect.
It's only the last post that made me look back through it (I thought if it worked in the browser, it would work in LC).
stupidly the error is in one of the variables - there is a space between the first and second name of the artist!!!!!!
so I put the 2 together and used urlencode, al good.
thanks v much again
Paul