1

I'm trying to send a URL with aFLickr API key to fetch results for a given photo tag. The Ajax code should return the XML to my browser. However the URL structure with parameters seems to cause a problem in my setup:

**the HTML file:**
...
url="api.flickr.com/services/rest/?method=flickr.photos.search&api_key=75564008a468bf8a284dc94bbd176dd8&tags=paris"

request.open("GET","xmlget.php?url=" + url + nocache, true)
...

**the 'xmlget.php' file:**
...
echo file_get_contents($_GET['url']);
...

error: code="100" msg="Invalid API Key (Key has invalid format)">

the link works fine if tested in the adress bar so there must be a breakdown somewhere when the URL is processed.

i tried wrapping it into encodeURI but no luck :(

Note: related post

Community
  • 1
  • 1

1 Answers1

0

You need to use encodeURIComponent instead of encodeURI to actually get that string encoded.

May I make 2 suggestions?

  • just pass the search parameters to xmlget.php and do the rest there even if it means having to pass a service type if you are using that generically
  • I don't remember what all a Flickr api key gets you, but it's generally a bad thing to post anything called an "api key" in public. In addition to the question, that includes sticking it in javascript that an end user can access.
jesse
  • 470
  • 2
  • 6
  • Hi jesse, thanks for the suggestion. it doesn't make a difference unfortunately. re api key, it seems that Flickr just need that to get some stats on usage of their API's so i don't think it's a problem. re the other suggestion i might try but for now i'll stick to this approach as i got it from a text book although their example was simpler than mine –  Mar 19 '11 at 00:33
  • your suggestion worked for me! i did some tweaking i.e. adding URL into a variable then applying the encoding: $search = encodeURIComponent($search). Now the full URL is being processed –  Mar 19 '11 at 15:27