PHP Code to Shorten URL Using Bitly API

Url shortening is attached with many benefits like social media friendliness and micro blogging usability, better SEO compatibility, ease of sharing, analytic data grossing, and most importantly the shortened URLs look more sober to eyes than usual orthodox long URLs.

There are many names, providing URL shortening services. Amongst all, Bitly is the most popular because of its reliability and other useful features. In this tutorial we will learn URL shortening using Bitly API

Steps to Create Shorten URL Using Bitly API

Firstly, create an account on Bitly by going to URL below:

https://bitly.com/a/sign_up

After registering on Bitly ,you need to create an app on Bitly.

Please go to the url:

https://dev.bitly.com/

and click My Apps -> Manage My apps and then Register an application.

Now, you must have an access token to make an api call. For this click Get Registration Code .

bilty3

You will receive an email on your registered email address, containing a link to take you for registering your first application.

Just fill the required details and click Create Your App button. You will be redirected to page showing client Id and client secret token for your application.

Again insert your password to generate access token.

bilty5

Now use this access token in the following code to make you first call to Bitly API.

Using above php code you can easily implement Bitly API to shorten your web post url.

Recommended Posts For You

About Manish Kumar

I am PHP web developer and blogger.

View all posts by Manish Kumar

1 thought on “PHP Code to Shorten URL Using Bitly API”

  1. Hi. Although I am very new to PHP, I managed to generate a Bitly URL using the codes you provided above.

    Unfortunately, I am just one step away from success. Bitly doesn’t seem to recognize the “&” characters in URL.

    The long URL parsed to Bitly is:
    http://mydomain.com/calculator?TokenA=APPLE&PriceA=5.061&TokenB=ORANGE&PriceB=3.02&QuantityB=90.44&PriceAend=7.76&PriceBend=2.287&RewardPrice=2.2&RewardQuantity=14.88&submit=SHOW+ME+MONEY

    When I clicked on the shortened URL, it went to:
    http://mydomain.com/calculator?TokenA=SHIB
    And because of this error, the calculator page failed to show the proper result. It seems that something is not right with the “&” character.

Leave a Comment

Your email address will not be published. Required fields are marked *