Hi guys,

Few days back I created an utility for checking the status of user if he/she is online on Yahoo Messenger.

This is a simple utility. Hope you guys have fun using it. 😉 images

Yahoo provides a link for accessing the status of user on Messenger. All you need to write a code that consume a REST web service.

Few days back I published a piece of code to consume REST webservices in Java. We will be using the same code here. In case you want to check this, here is the link for that post: https://blog.niteshapte.com/2013-11-08-how-to-consume-rest-web-service-in-java.htm

Now, back to the point. 😉 The link provided by Yahoo: http://opi.yahoo.com/online?u=yahoo-messenger-id&m=a

And the code:

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Scanner;

public class YahooMessengerStatusCheck {

        public String checkStatus(String yahooID) {

                String response = null;
                try {

                        URL url = new URL("http://opi.yahoo.com/online?u=" + yahooID +"&m=a"); 
                        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                        conn.setDoOutput(true);
                        conn.setRequestMethod("GET");
                        conn.disconnect();                

                        InputStream is = conn.getInputStream();
                        Scanner isScanner = new Scanner(is);

                        StringBuffer buf = new StringBuffer();
                        while(isScanner.hasNextLine()) { 
                                buf.append(isScanner.nextLine());
                        }
                        response = buf.toString();
               
         System.out.println(response);

                } catch (IOException e) { 
                        e.printStackTrace();
                }               
                return response;
        }

        public static void main(String[] args) {
                new YahooMessengerStatusCheck().checkStatus("yahooID-of-user");
        }
}

The output that will be displayed on console will be like:
yahooID is ONLINE (in case user is online) or yahooID is NOT ONLINE (if user is offline).

So that’s it guys! Have fun using this utility.

Critics/feedback are very much welcome.

Have  a nice day ahead!

Loading