buy clomid online

Archive for the 'twitter' Category

Convert Short Url to Long Url with Java

June 07th, 2012 | Category: geek,java,twitter

Wikipedia :

Twitter is an online social networking service and microblogging service that enables its users to send and read text-based posts of up to 140 characters, known as “tweets”.

In microbloging service like Twitter , User must limit the text to 140 characters and URL can be some time very long. Some compagnies(Bitly, TinyURL,…) offer service to reduce your URL with a result like this
In some situation, you have to transform short url to the original to analyse some tweets. For this, technically, you must follow the redirection to get this URL. My solution is to have a loop reading the content of the header and to be more specific the field location until the last URL.
The result :

  1. package;
  3. import;
  4. import;
  5. import;
  6. import;
  7. import;
  9. /**
  10.  *
  11.  * @author Nihed MBAREK
  12.  */
  13. public class UrlTools {
  15.     public static String getLongUrl(String shortUrl) throws MalformedURLException, IOException {
  16.         String result = shortUrl;
  17.         String header;
  18.             do {
  19.                 URL url = new URL(result);
  20.                 HttpURLConnection.setFollowRedirects(false);
  21.                 URLConnection conn = url.openConnection();
  22.                 header = conn.getHeaderField(null);
  23.                 String location = conn.getHeaderField("location");
  24.                 if (location != null) {
  25.                     result = location;
  26.                 }
  27.             } while (header.contains("301"));
  29.         return result;
  30.     }
  31. }

Now, you can call this method in your class like this :

  1. String result = UrlTools.getLongUrl("");

ps: waiting for your questions 🙂


Twitter Search with Ruby

November 16th, 2010 | Category: Ruby,twitter

Ruby is one of the most powerful language with the number of GEM’s (Packages) that can be used to connect on every component of internet.
For twitter, GEM’s are available, one of them “twitter” can do for you what you want.
To install :

  1. $ sudo gem install twitter

Next, you can write your code to do what you want (Search for our example) .
To begin this sample, we must know some useful option for search :

  • from(“XXXX”) : to define the sender of our messages
  • to(“XXXX”) : to define the receiver of our messages
  • since_date(“YYYY-MM-DD”) : to get tweets after a given date

For more information :
And our code will be :

  1. require ‘rubygems’
  2. require ‘twitter’
  3. #search for the word nihed since 01/11/2010
  4.‘nihed’).since_date("2010-11-01").each do |r|
  5.   puts r.from_user+": "+r.text+"\n\n"
  6. end

Like we can see, with ruby, we have a simple and beautiful code.
For more information :
Twitter Search API Method

1 comment