url_expander icon indicating copy to clipboard operation
url_expander copied to clipboard

Problem with bit.ly API

Open blackerby opened this issue 13 years ago • 2 comments

Thought I was clever enough to fork this and figure it out, but I've still got too much n00b in me. Any idea what's happening here?

ruby-1.9.2-p180 :015 > UrlExpander::Client.expand("http://bit.ly/qpshuI")
TypeError: can't convert String into Integer
    from /Users/wm/.rvm/gems/ruby-1.9.2-p180/gems/url_expander-0.1.5/lib/url_expander/expanders/api/bitly.rb:57:in `[]'
    from /Users/wm/.rvm/gems/ruby-1.9.2-p180/gems/url_expander-0.1.5/lib/url_expander/expanders/api/bitly.rb:57:in `fetch_url'
    from /Users/wm/.rvm/gems/ruby-1.9.2-p180/gems/url_expander-0.1.5/lib/url_expander/expanders/api/bitly.rb:34:in `initialize'
    from /Users/wm/.rvm/gems/ruby-1.9.2-p180/gems/url_expander-0.1.5/lib/url_expander.rb:39:in `new'
    from /Users/wm/.rvm/gems/ruby-1.9.2-p180/gems/url_expander-0.1.5/lib/url_expander.rb:39:in `expand'
    from (irb):15
    from /Users/wm/.rvm/rubies/ruby-1.9.2-p180/bin/irb:16:in `<main>'

I messed around in irb with the code in the 'fetch_url' method and that worked fine, specifically this part (lines 57-59):

data = JSON.parse Request.get("/v3/expand?hash=#{@shortner_key}&login=#{@login}&apiKey=#{@api_key}").response.body
expand = data['data']['expand'].first
if(data['status_code'] == 200 && !expand.has_key?('error'))
  @long_url = expand["long_url"]

Great project, maybe as I learn some more I'll be able to help out with some code!

blackerby avatar Aug 29 '11 23:08 blackerby

Interesting ... it seems there is a response from bitly i am not parsing correctly .... are you sure your bitly login and key are correct and can you give a sample url you are trying to expand ?

moski avatar Sep 04 '11 08:09 moski

I was receiving this error, fixed it by lower casing my login credential for bit.ly

AaronKalair avatar Dec 10 '12 10:12 AaronKalair