how to implement a short url like urls in twitter?

后端 未结 4 1772
甜味超标
甜味超标 2020-12-01 00:10

If there is a long url, i want to generate a short url like those in twitter, is there some way to implement in ruby?

Thank you in advance.

4条回答
  •  情书的邮戳
    2020-12-01 01:02

    I use the bitly gem. It's really simple.

    gem install bitly
    
    # Use api version 3 or get a deprecation warning
    Bitly.use_api_version_3
    
    # Create a client
    bitly = Bitly.new(username, api_key)
    
    # Call method shorten
    bitly.shorten('http://www.google.com').short_url
    

提交回复
热议问题