vote up 0 vote down star

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.

flag

3 Answers

vote up 1 vote down check

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

link|flag
vote up 1 vote down

They probably expect a POST request rather than a GET.

link|flag
In fact, GET is allowed. – Iamamac Jan 2 at 18:35
vote up 1 vote down

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" }
link|flag
Right but not the main issue. There would be a response even if the URL is invalid. – Iamamac Jan 2 at 18:40

Your Answer

Get an OpenID
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.