tags:

views:

219

answers:

3

I tried to call bit.ly API using this jQuery script:

$.get('http://api.bit.ly/shorten?login=bitlyapidemo&apiKey=R_0da49e0a9118ff35f52f629d2d71bf07&version=2.0.1&longUrl=www.wordpress.com', function(data) { alert(data); });

but firebug said "405 Method Not Allowed". What's wrong? Thanks a lot.

A: 

They probably expect a POST request rather than a GET.

Azeem.Butt
In fact, GET is allowed.
Iamamac
A: 

The URL is not valid.

You have to put the http:// in front of the longUrl argument.

Edit

Some clarifications:

This url http://api.bit.ly/shorten?login=bitlyapidemo&apiKey=R_0da49e0a9118ff35f52f629d2d71bf07&version=2.0.1&longUrl=http://www.wordpress.com returns

{ "errorCode": 0, "errorMessage": "", "results": { "www.wordpress.com": { "errorCode": 1206, "errorMessage": "URL you tried to shorten was invalid.", "statusCode": "ERROR" } }, "statusCode": "OK" }

this one: http://api.bit.ly/shorten?login=bitlyapidemo&apiKey=R_0da49e0a9118ff35f52f629d2d71bf07&version=2.0.1&longUrl=http://www.wordpress.com returns

{ "errorCode": 0, "errorMessage": "", "results": { "http://www.wordpress.com": { "hash": "j1IP3", "shortKeywordUrl": "", "shortUrl": "http://bit.ly/6i1NkN", "userHash": "6i1NkN" } }, "statusCode": "OK" }
Loïc Wolff
Right but not the main issue. There would be a response even if the URL is invalid.
Iamamac
+1  A: 

$.get do not support cross-domain GET.

You can use JSONP technique, and $.getJSON.

BTW, http:// should in the longUrl parameter of bit.ly API call. But it's not the main problem.

Iamamac