How much one URL went viral ? It is based on the shares of that URL on social networking websites. How to get those share counts ?...Here in this tutorial I am going to explain how to get those share count.

Twitter

Get URL
Output
{"count":11,"url":"http:\/\/pojo.sodhanalibrary.com\/"}
Implementation with Java
String url ="https://cdn.api.twitter.com/1/urls/count.json?url=http://pojo.sodhanalibrary.com"; 
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
//add request header
con.setRequestProperty("User-Agent", USER_AGENT);

// Send request
System.out.println("\nSending 'GET' request to URL : " + url);
BufferedReader in = new BufferedReader(
       new InputStreamReader(con.getInputStream()));
String outputLine;

// reading output from Request
StringBuffer response = new StringBuffer(); 
while ((outputLine = in.readLine()) != null) {
   response.append(outputLine);
}
in.close();

Facebook

Get URL
Output
{
   "id": "http://pojo.sodhanalibrary.com",
   "shares": 27
}
Implementation with Java
String url ="http://graph.facebook.com/?id=http://pojo.sodhanalibrary.com"; 
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
//add request header
con.setRequestProperty("User-Agent", USER_AGENT);

// Send request
System.out.println("\nSending 'GET' request to URL : " + url);
BufferedReader in = new BufferedReader(
       new InputStreamReader(con.getInputStream()));
String outputLine;

// reading output from Request
StringBuffer response = new StringBuffer(); 
while ((outputLine = in.readLine()) != null) {
   response.append(outputLine);
}
in.close();

System.out.println(response.toString());

Pinterest

Get URL
Output
receiveCount({"url":"http://pojo.sodhanalibrary.com","count":0})
Implementation with Java
String url ="http://api.pinterest.com/v1/urls/count.json?url=http://pojo.sodhanalibrary.com"; 
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
//add request header
con.setRequestProperty("User-Agent", USER_AGENT);

// Send request
System.out.println("\nSending 'GET' request to URL : " + url);
BufferedReader in = new BufferedReader(
       new InputStreamReader(con.getInputStream()));
String outputLine;

// reading output from Request
StringBuffer response = new StringBuffer(); 
while ((outputLine = in.readLine()) != null) {
   response.append(outputLine);
}
in.close();
System.out.println(response.toString());

Linkedin

Get URL
Output
IN.Tags.Share.handleCount({"count":0,"fCnt":"0","fCntPlusOne":"1","url":"http:\/\/pojo.sodhanalibrary.com"});
Implementation with Java
String url ="http://www.linkedin.com/countserv/count/share?url=http://pojo.sodhanalibrary.com"; 
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
//add request header
con.setRequestProperty("User-Agent", USER_AGENT);

// Send request
System.out.println("\nSending 'GET' request to URL : " + url);
BufferedReader in = new BufferedReader(
       new InputStreamReader(con.getInputStream()));
String outputLine;

// reading output from Request
StringBuffer response = new StringBuffer(); 
while ((outputLine = in.readLine()) != null) {
   response.append(outputLine);
}
in.close();
System.out.println(response.toString());

0 comments:

Blogroll

Follow this blog by Email

Popular Posts