Can't post keywords with double-quotes
darryl
Registered Users Posts: 997 Major grins
Man, this is super-frustrating.
In the web UI, if you enter a keyword in "double quotes", as advised by the help pages, it ends up in the database (as retrieved by images.getInfo) as "double quotes".
Fine, I can [post=657463]parse for that[/post]. But when I go to write keywords back out, I'm trying to use the API like so:
If $newkeywordstext contains double-quotes (ex. "ty"), they appear in the web UI prepended with a \, and when I go back with an images.getInfo call, it shows up as:
\"ty\"
Blech. Ok, maybe I should try to HTML encode the double-quotes myself. So I try posting: "ty"
This time images.getInfo gives me the equally ugly:
"ty"
Nasty. I don't want to use semi-colons! Double-quotes make sense to me and to the non-coders that may be editing keywords. Also, I *need* double-quotes so that keywords < 4 characters will be recognized as keywords. Argh!
Any other suggestions on getting the API to properly accept double-quote characters? It kind of sucks when functionality on the website isn't duplicated in the API.
In the web UI, if you enter a keyword in "double quotes", as advised by the help pages, it ends up in the database (as retrieved by images.getInfo) as "double quotes".
Fine, I can [post=657463]parse for that[/post]. But when I go to write keywords back out, I'm trying to use the API like so:
$changeinfo = $browser->post('http://api.smugmug.com/hack/rest/1.2.0/', ['method'=>'smugmug.images.changeSettings', 'SessionID'=>"$sessionid", 'ImageID'=>"$updateimage", 'Keywords'=>"$newkeywordstext"],) ;
If $newkeywordstext contains double-quotes (ex. "ty"), they appear in the web UI prepended with a \, and when I go back with an images.getInfo call, it shows up as:
\"ty\"
Blech. Ok, maybe I should try to HTML encode the double-quotes myself. So I try posting: "ty"
This time images.getInfo gives me the equally ugly:
&quot;ty&quot;
Nasty. I don't want to use semi-colons! Double-quotes make sense to me and to the non-coders that may be editing keywords. Also, I *need* double-quotes so that keywords < 4 characters will be recognized as keywords. Argh!
Any other suggestions on getting the API to properly accept double-quote characters? It kind of sucks when functionality on the website isn't duplicated in the API.
0
Comments
On the site, only the last one actually resulted in the keyword being properly recognized.
It's annoying though that if you manually type "ty" on the site, it turns into: "ty" without the extraneous backslashes.
I ran into this issue as well. What is the recommened practice for submitting keywords with double quotes via the API? Thanks.
If human users end up looking at that keyword, they'll see:
\"this sucks\"
And using the API call to get quotes, I still get \"this sucks\"
I couldn't find any way around it, so I just use this annoying regexp to fix it before I start to deal with keywords:
$oldkeywords =~ s|\\"|"|g ;
Here's my whole [post=684695]keyword parsing subroutine[/post]
Luke,
You can use semi-colons to seperate keywords, eg.
keyword1; keyword two; more key words;
Cheers,
David
SmugMug API Developer
My Photos
I have the following keywords:
5 star hotel; indianapolis;
The 5 star hotel keyword does not show up when viewing the page, but will show up when I edit my keywords. It works with double-quotes, excepting the API bug.
Is there any new info on this? I'm having a very similar problem with at least my captions and my keywords.
Using the 1.2.0 JSON interface, posting a string that starts and ends with a ", leads to the entire string being escaped, causing some interesting problems.
Using an older XML-RPC interface did NOT have the problem, and the text appears as entered.
SmugMug API Developer
My Photos
Thanks David!
Please let me know if you have any issues.
SmugMug API Developer
My Photos