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());

4 comments:


  1. Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well.
    I wanted to thank you for this websites! Thanks for sharing. Great websites!

    Pubg APK

    Pubg mobile APK

    ReplyDelete
  2. Your blogs are great.Are you also searching for nursing pico writing help? we are the best solution for you. We are best known for delivering nursing writing services to students without having to break the bank.

    ReplyDelete
  3. Thank you very much for providing this information! You literally rescued my day! After hours of attempting to get Facebook Loin to function with Java, I got here and found the answer. I hope you can share more post like this one in the future. Anyway, I want to return the favor by sharing this link - https://games.lol/idle-theme-park-tycoon/. Download this game and have fun. And read the details about Games.lol safety here if you want to make sure that the website is secured and free.

    ReplyDelete
  4. This tutorial provides a comprehensive guide on retrieving URL share counts from various social networking sites using Java. It offers step-by-step implementations for Twitter, Facebook, Pinterest, and LinkedIn, making it a valuable resource for developers looking to integrate social sharing analytics into their applications.

    I appreciate the clarity and conciseness of the code examples provided, which make it easy to understand and implement the necessary HTTP requests to each social platform's API.

    As I explore this tutorial further, I'm curious: How would you recommend handling errors or exceptions that may arise during the HTTP requests? Additionally, are there any best practices for optimizing the performance of these requests, especially when dealing with a large number of URLs?
    https://blitzacademy.org/coursedetail.php?course_cat=9&course_id=6&cyber-forensic-courses-in-kerala

    Overall, this tutorial serves as a valuable reference for developers seeking to incorporate social sharing metrics into their Java applications. Great job!

    ReplyDelete

Blogroll

Popular Posts