PHP class for expanding and shortening URLs using Google URL shortener API

I have combined the 2 previous posts for expanding and shortening goo.gl URLs and have created a small class for it. Below is the download link for the class.

Download GAPIClass

Expanding a URL

Shorten A URL

As I have mentioned earlier that Google recommends an API key. The class has a flag variable called keyWarning. By default it is true and it will show the following warning message if you do not pass an API key while instantiating the class:

Currently you are not using an API key. It is recommended that you use one. Click here to learn more about the API key

To turn this notification off, just use this line:

Download GAPIClass

PHP: Shorten URLs using Google URL shortener API

In past 2 posts you saw how short URLs can be expanded using the Google URL shortener API. This post shows how URLs can be shortened using this API.

API key is not mandatory for test purpose. Use this link to get an API key.

For shortening URLs, 2 points must be noted. First, a HTTP POST is required and the post data should be in JSON format. Here is the code:

Here is the JSON response from Google:

You can also read these:

Using PHP and cURL to expand URLs using Google URL shortener API

Yesterday I wrote this post explaining how short goo.gl URLs can be expanded using the newly launched goo.gl API. In that code we used php function get_file_contents to get the response from API.

How about implementing the same functionality using cURL now? If you have libcurl support installed with PHP, you are ready to use the cURL functions of PHP.

Here is the code. API key is not mandatory but Google recommends that you use one. It will increase your per day usage limits too. Follow this link to get an API key.

And here is the full JSON response:

Am important point to note. Since the API is on https, set the value for CURLOPT_SSL_VERIFYPEER to false. This will stop cURL from verifying the SSL certificate.

PHP: Expanding URLs using Google URL shortener API

Yesterday. google launched an API for its URL shortening service http://goo.gl. Using this API developers will be able to expand/shorten URLs and get a user’s analytics and history programmaticaly.

Below is a small snippet of PHP code that expands a short URL. The response comes in JSON format, so we will use the json_decode function to convert it to object.

Here is the full successfull response in JSON format.

Finally, note that Google recommends the use of an API key. You can visit this link to read more about key and get a key from this link.

After using the key, your URL will look like the following:

Using Twitter API and jQuery to display recent tweets

In this article I will show you how you can display your (or any other user’s) recent tweets with some jQuery magic. We will create a widget (sort of) that will fetch n number of latest tweets from public timeline of a user using Twitter API and then we will display them in a nice list.

End result will look like the following.

tweets

Have a look at a live example.

View Demo

Let us start creating it now. First write some HTML. Define some css styles in the head section which will control the display of list. In the body section, there is a select box with id layout which will be used to select either a wide or a narrow layout for displaying the tweets. Then create a div with id tweets. We will create a ul inside this div which will have tweets as list items.

Continue reading Using Twitter API and jQuery to display recent tweets