开发者

AJAX & PHP:GET parameters causing Flickr api key error

I'm trying to send a URL with aFLickr API key to fetch results for a given phot开发者_StackOverflowo 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


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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜