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:
After registering on Bitly ,you need to create an app on Bitly.
Please go to the url:
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 .
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.
Now use this access token in the following code to make you first call to Bitly API.
$access_token = '**** INSERT ACCESS TOKEN HERE ****';
$url = 'https://api-ssl.bitly.com/v3/shorten?access_token='.$access_token.'&longUrl='.$long_url;
$ch1 = curl_init($url); //open connection
curl_setopt($ch1, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1 );
$result = curl_exec($ch1); //execute post
$data_array = json_decode($result);
echo 'Long url: '.$long_url.'<br>';
echo 'shortened url: '.$data_array->data->url;
Using above php code you can easily implement Bitly API to shorten your web post url.