a little confused on how the bit.ly API works

111 views
Skip to first unread message

tubbo

unread,
Nov 25, 2009, 10:04:30 PM11/25/09
to bitly API
i've been doing some cURL experiments to see what output the bit.ly
API will give me. i'm trying to write a function for my Rails-based
blog that posts the title & shortened URL of the blog post to Twitter
upon completion.

i am accomplishing this by sending the following cURL command in Ruby:

$ curl http://api.bit.ly/shorten?version=2.0.1&longUrl=http://psychedeli.ca/blog/posts/1&login=mylogin&apiKey=R_MYAPIKEY

This command, when sent through the Terminal, fails. Here's the error
(in JSON):
{
"errorCode": 203,
"errorMessage": "You must be authenticated to access shorten",
"statusCode": "ERROR"
}

When I try to authenticate (via -u mylogin:mypassword),

$ curl -u tubbo:tom94263 http://api.bit.ly/shorten?version=2.0.1&longUrl=http://psychedeli.ca

the bit.ly API also gives me an error:
{
"errorCode": 201,
"errorMessage": "Missing parameter longUrl",
"statusCode": "ERROR"
}

I've tried URL-escaping the longUrl, adding & removing the login/
apiKey combo when I authenticate via HTTP, moving the variables around
in the URL string, everything. I'm not sure what to do, this API seems
to be behaving abnormally with my machine. Note that other APIs
accessed through cURL (Twitter) work perfectly.

Jehiah Czebotar

unread,
Nov 25, 2009, 10:38:35 PM11/25/09
to bitl...@googlegroups.com
Hi tubbo, the first method is correct, the second isn't.

I tried exactly that url (with my login and api key) and it worked fine.

here is the output i get:

curl -v 'http://api.bit.ly/shorten?version=2.0.1&longUrl=http://psychedeli.ca/blog/posts/1&login=j3h14h&apiKey={{apikey}}'
* About to connect() to api.bit.ly port 80 (#0)
* Trying 168.143.174.25... connected
* Connected to api.bit.ly (168.143.174.25) port 80 (#0)
> GET /shorten?version=2.0.1&longUrl=http://psychedeli.ca/blog/posts/1&login=j3h14h&apiKey={{apikey}} HTTP/1.1
> User-Agent: curl/7.19.4 (universal-apple-darwin10.0) libcurl/7.19.4 OpenSSL/0.9.8k zlib/1.2.3
> Host: api.bit.ly
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: nginx/0.7.42
< Date: Thu, 26 Nov 2009 03:31:58 GMT
< Content-Type: text/html;charset=utf-8
< Connection: keep-alive
< Content-Length: 303
< Allow: GET, HEAD, POST
< Set-Cookie: anonu=psu__071b79af-5868-4fb3-9eb8-257efae46918---f8ed2a34a39863e7fb88d5a2520b4288;
Domain=.bit.ly; expires=Wed, 26-Oct-2011 22:31:58 GMT; Path=/;
Version=1
< Set-Cookie: bsession=60246b63-1f2a-483e-b047-c26cfd150703---56732534f10baa01bc4a7eb59e96bb16;
Domain=.bit.ly; expires=Wed, 26-Oct-2011 22:31:58 GMT; Path=/;
Version=1
<
{
"errorCode": 0,
"errorMessage": "",
"results": {
"http://psychedeli.ca/blog/posts/1": {
"hash": "6DTVSa",
"shortKeywordUrl": "",
"shortUrl": "http://bit.ly/6Z7hqy",
"userHash": "6Z7hqy"
}
},
"statusCode": "OK"
* Connection #0 to host api.bit.ly left intact
* Closing connection #0
}

---

so, can you email a full -v trace to sup...@bit.ly so we can
troubleshoot further?

you can also double-check your api key here http://bit.ly/account/your_api_key

also, you should encode the individual components of your api call, so
the longUrl should really be
http%3A%2F%2Fpsychedeli.ca%2Fblog%2Fposts%2F1

--
Jehiah
> --
>
> You received this message because you are subscribed to the Google Groups "bitly API" group.
> To post to this group, send email to bitl...@googlegroups.com.
> To unsubscribe from this group, send email to bitly-api+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/bitly-api?hl=en.
>
>
>

Jehiah Czebotar

unread,
Nov 25, 2009, 10:44:17 PM11/25/09
to bitl...@googlegroups.com
It just occurred to me that the problem might just be that you are not
putting quotes around the url you are passing to curl on the command
line.

"&" mans something else on a linux command line, so you need to quote
the whole string like i did in my exmaple. Without that & puts the
process in the background, and the rest of the url won't get handled
by curl, which is most likely causing the api key and login to be left
off

-v which turns on verbose logging from curl is also a good idea as it
helps identify that sort of thing.

--
Jehiah

Phil Nash

unread,
Nov 26, 2009, 3:51:50 AM11/26/09
to bitl...@googlegroups.com
Hi Tubbo,

If it's a Rails based blog, then why not use the gem that I built for the Bitly API. Check it out at http://github.com/philnash/bitly and install with gem install bitly.

Phil

--
Phil Nash

Twitter: http://twitter.com/philnash
Find some music: http://yournextfavband.com
SpotifiTunes: http://spotifitunes.com


tubbo

unread,
Dec 15, 2009, 12:59:47 AM12/15/09
to bitly API
THANK YOU Jehiah for identifying my problem, and thank you Phil for
that useful information. I'll check out that gem once GitHub comes
back.

On Nov 26, 3:51 am, Phil Nash <philn...@gmail.com> wrote:
> Hi Tubbo,
>
> If it's a Rails based blog, then why not use the gem that I built for the
> Bitly API. Check it out athttp://github.com/philnash/bitlyand install with
> gem install bitly.
>
> Phil
>
> --
> Phil Nash
>
> Twitter:http://twitter.com/philnash
> Find some music:http://yournextfavband.com
> SpotifiTunes:http://spotifitunes.com
>
>
>
> On Thu, Nov 26, 2009 at 3:04 AM, tubbo <tu...@psychedeli.ca> wrote:
> > i've been doing some cURL experiments to see what output the bit.ly
> > API will give me. i'm trying to write a function for my Rails-based
> > blog that posts the title & shortened URL of the blog post to Twitter
> > upon completion.
>
> > i am accomplishing this by sending the following cURL command in Ruby:
>
> > $ curl
> >http://api.bit.ly/shorten?version=2.0.1&longUrl=http://psychedeli.ca/...
>
> > This command, when sent through the Terminal, fails. Here's the error
> > (in JSON):
> > {
> >    "errorCode": 203,
> >    "errorMessage": "You must be authenticated to access shorten",
> >    "statusCode": "ERROR"
> > }
>
> > When I try to authenticate (via -u mylogin:mypassword),
>
> > $ curl -u tubbo:tom94263
> >http://api.bit.ly/shorten?version=2.0.1&longUrl=http://psychedeli.ca
>
> > the bit.ly API also gives me an error:
> > {
> >    "errorCode": 201,
> >    "errorMessage": "Missing parameter longUrl",
> >    "statusCode": "ERROR"
> > }
>
> > I've tried URL-escaping the longUrl, adding & removing the login/
> > apiKey combo when I authenticate via HTTP, moving the variables around
> > in the URL string, everything. I'm not sure what to do, this API seems
> > to be behaving abnormally with my machine. Note that other APIs
> > accessed through cURL (Twitter) work perfectly.
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "bitly API" group.
> > To post to this group, send email to bitl...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > bitly-api+...@googlegroups.com<bitly-api%2Bunsubscribe@googlegroups .com>
> > .

Phil Nash

unread,
Dec 15, 2009, 4:17:03 AM12/15/09
to bitl...@googlegroups.com
No worries, hope it helps out. The link seems broken in that last email, so I'll just add it again: http://github.com/philnash/bitly

You can just, gem install bitly to install it too.

Let me know if you have any problems with it,


Phil
--
Phil Nash

Twitter: http://twitter.com/philnash
Find some music: http://yournextfavband.com
SpotifiTunes: http://spotifitunes.com


To unsubscribe from this group, send email to bitly-api+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages