Bitly is used to shorten, brand, share, or retrieve data from links programmatically.
In this article, we’ll see how to shorten URLs using Bitly API. Below is a working example to shorten a URL using Bitly API.
Step #1: Install Bitly API using git
git clone https://github.com/bitly/bitly-api-python.git
Go inside the folder using:
Note: In case installation with pip command is not working:
Uninstall bitly-api in case already installed using pip:
pip uninstall bitly_api
Step #2: Install in Python’s folder for modules:
python setup.py install
Note: Delete the source code using (since we don’t need it for now) :
cd../ rmdir bitly-api-python-master
Step #4: Now create a file
shorturl.py and write this code:
Step #5: Run the file ‘shorturl.py’.
- Comprehensions in Python
- Calendar in Python
- URL Shorteners and its API in Python | Set-2
- URL Shorteners and its API in Python | Set-1
- Namedtuple in Python
- ChainMap in Python
- Whatsapp using Python!
- MongoDB and Python
- Profiling in Python
- Polymorphism in Python
- Running Python script on GPU.
- Python | Using for loop in Flask
- Namespaces and Scope in Python
- Keyboard module in Python
- Python | Lemmatization with TextBlob
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.