Sign In Create Account
How to Shorten a Link, by hilarymason
  1. Current: Shorten a link!
Shorten a link!

This exercise will walk you through giving the bitly API a long URL and getting back a short link.

Shortening a URL is very straightforward -- you give the API the long URL (the characters that you see above the page) and it gives you back a short URL that redirects to that long URL.

Instructions

The shorten API endpoint runs a function that looks for a longUrl and returns a short URL.

Using the example, change the longUrl parameter to be a link to a web page that you've enjoyed recently (possibly even this one)! The longUrl must contain the full URL, including the 'http://' protocol.

The JSON response is a dictionary with several values. Try printing just the short link, which you can find in the ['data']['url'] key.

Files:
script.py
Back to Editor
Start Here

Each lesson starts here. Read the explanation, then follow the instructions underneath. If you get stuck, you can click on the "Hint" for help.

Next  →
Enter your Code

Type your response to the instructions here, in your code editor.

Next  →
See What it Does

Ready to see if your code does what it should? Click "Save + Submit" to run and check your code!

Click "Save + Submit" to run your code! Your code’s output will pop up on the screen.

Next  →
Submit!

This is the terminal. When you submit your code, it will run your code and display the result here.

I'm ready!

Sign in to Codecademy