Tag Archives: API’s/Webservices

Code sample to access YQL from PHP

Just wrote quick some code sample to show how to access YQL (Yahoo Query Language) queries from PHP.

You can use the following code sample to fetch results from YQL from any standard PHP file. You would require the curl extension to be installed. If you are behind a proxy, uncomment the 3 lines and replace it with proper proxy values

If you have the Yahoo social SDK installed and you want to access results from YQL, then you can use the following code sample. Replace the text consumer_key and consumer_secret with correct values.

Update: You can also get code snippets for other languages apart from PHP.

Posted in API's/Mashup, Web Programming | Tagged , , | 2 Comments

Associating urls created with bit.ly API to your account

Recently while working on adding the feature to enter your own bit.ly API key to my Easy Retweet WordPress Plugin, I found out that by default all short urls created using bit.ly API (both REST and JavaScript API’s) are not associated with your account.

Upon further researching I found that there is an undocumented way of associating the urls created with your account. The undocumented way is to add an additional parameter called history with value 1 to the API URL.

Using the history parameter in bit.ly’s REST API

So for REST API, you have to use the following url.


If you are using PHP, then code would be

function get_bitly_shorturl($longurl) {
	$url = "http://api.bit.ly/shorten?version=2.0.1&login=bitlyapidemo&apiKey=R_0da49e0a9118ff35f52f629d2d71bf07&format=json&history=1" . "&longurl=$longurl";

	//using curl
	$curlObject = curl_init();

	$result_json = curl_exec($curlObject);

	//decode JSON. Assumes that it is PHP5
	$result = json_decode($result_json);

	return $result['results'][shortUrl];

If you are going to use it in WordPress, then you can use the inbuilt WP_Http class instead of curl as suggested by Ozh. The following code shows you how it can be done in WordPress

function get_bitly_shorturl($longurl) {
	$url = "http://api.bit.ly/shorten?version=2.0.1&login=bitlyapidemo&apiKey=R_0da49e0a9118ff35f52f629d2d71bf07&format=json&history=1" . "&longurl=$longurl";

	//using WP_Http present in WordPress
	$request = new WP_Http;
	$result_json = $request->request($url);

	$result = json_decode($result_json);

	return $result['results'][shortUrl];

Using the history parameter in bit.ly’s JavaScript API

If you are using bit.ly’s JavaScript API, then it is not as straight forward as the REST API. Instead of using the provided shorten method, you have to use the low level call method.

The following code shows you how you can do it in JavaScript API.

BitlyClient.call('shorten', {'longUrl':'http://sudarmuthu.com', 'history':'1'}, 'BitlyCB.shortenResponse');

I am not sure why bit.ly is not associating the created shorturls automatically with your account, when you provide the API Key, it is the expected default behavior. Or at least they could have documented about this history variable in their API. I guess only someone from bit.ly can answer this. 🙂

Posted in API's/Mashup, JavaScript/jQuery, WordPress | Tagged , , | 8 Comments

Using FriendFeed API in your WordPress Plugin

I am working on some new features for my Post to FriendFeed WordPress Plugin, and it required some additional methods to the FriendFeed API wrapper. I have added these methods to the FriendFeed API wrapper and have released it as a separate Plugin like Open Flash Chart Core Plugin.

Additional Methods

The following are the additional methods that I have added to the FriendFeed API wrapper library.


This method accepts users nickname as input and returns the list of all of the user’s subscriptions (people) and services connected to their account (Authentication required for private users)


This method accepts users nickname as input and returns the list of all of the rooms to which the user can post (Authentication required for private users)


You can download the Plugin file from my Plugin page and then upload it to your wp-contents directory.

If you are a WordPress Plugin developer, then you can check my FriendFeed API Core Plugin to find out how to integrate FriendFeed API with you own WordPress Plugins.

PS: Incidentally this is my first blog post from Windows Live Editor.

Posted in Plugin Releases | Tagged , , , , | 1 Comment

Bloglines Notifier – My First Google Gadget

Bloglines Notifier Google GadgetI didn’t have much to do last weekend and so I thought of giving a try to Google Gadget and ended up developing my first Google Gadget – Bloglines Notifier. As the name implies it will notify you the count of unread items in your Bloglines account. (Nothing special just a trivial one 😉 )

You need to enter your Bloglines account email id and it will retrieve the unread count using the Bloglines API and display it in the Gadget screen. The count will be automatically refreshed according to the interval set in the Gadget settings. Since Bloglines doesn’t need you to be authenticated before retrieving the unread count you don’t need to enter your Bloglines account password.

The Google Gadget API is very simple to start with but at the same time very powerful if you need to do complex or advanced things. If you are interested grab the Google Gadget API Developers Guide and get started. It’s actually that simple.

The full source code of this Gadget is available here and if you are interested you can add it to your personalized page by clicking this button. Add to Google

Now I can have one icon less in my system tray. 😉 BTW if you guys have a nice idea for a Gadget, let me know I shall give a try.

Resources Used

Posted in API's/Mashup | Tagged , , , , , | 2 Comments