/*
 * Copyright 2007 Yusuke Yamamoto
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package model;

import twitter4j.*;
import com.google.gson.Gson;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;

/**
 * @author Yusuke Yamamoto - yusuke at mac.com
 * @since Twitter4J 2.1.7
 */
public class LatestTweets {
    /**
     * Usage: java twitter4j.examples.search.SearchTweets [query]
     *
     * @param args search query
     */
    public static void main(String[] args){
        returnTweets("tarkariwali");
    }
    public static Object returnTweets(String genre) {
        
        String forreturn="";
       // forreturn.append("{\"trends\":[") ;
        
        Twitter twitter = new TwitterFactory().getInstance();
          //Object etc=new Object();
        
        
       // gl = new GeoLocation(latitude,longitude);
        try {
           // ResponseList tt;
           // tt = twitter.getClosestTrends(gl);
           // System.out.println(tt.toString());
          //  Object value=tt.get(0);
            //JSONObject loc;
         //  String loc=value.toString().substring(value.toString().indexOf("=")+1,value.toString().indexOf(","));
            
            //loc=gson.fromJson(value,Place).toJson();
               //         System.out.println(value.toString());

          //  int woeid=1;
         //   woeid=Integer.valueOf(loc);
         //               System.out.println("SearchTweet TEsting Console");

         //   Trends placeTrends = twitter.getPlaceTrends(woeid);
            
           // int count=0;
            Gson gson=new Gson();
                          

            
          //  etc=gson.toJson(forreturn);
            


            Query query = new Query(genre);
            query.setCount(8);
          //  GeoQuery query = new GeoQuery(new GeoLocation(Double.parseDouble(args[0]), Double.parseDouble(args[1])));
            QueryResult result;
           
             List<Tweet> returntweet=new ArrayList();
            
            
                result = twitter.search(query);
                List<Status> tweets = result.getTweets();
               // String etc;
               
                
               // System.out.println(etc);
                for (Status tweet : tweets) {
                    //System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText());
                    Tweet twit=new Tweet();
                    twit.setUserid(tweet.getUser().getScreenName());
                    twit.setText(tweet.getText());
                    twit.setUrl("http://twitter.com/"+twit.getUserid());
                    twit.setFullname(tweet.getUser().getName());
                    twit.setImgurl(tweet.getUser().getBiggerProfileImageURL());
                    returntweet.add(twit);
                   
               // forreturn.append(etc);
                  
                }
               
                    
            
            
            forreturn=gson.toJson(returntweet);
           System.out.print(forreturn);
            
        
        }catch (TwitterException te) {
            te.printStackTrace();
            System.out.println("Failed to search tweets: " + te.getMessage());
            System.exit(-1);
        }
         //  System.out.println(forreturn);

return forreturn;
    }
    
}

@@ -1,983 +1,187 @@
-/*%0A * Copyright 2007 Yusuke Yamamoto%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage model;%0A%0Aimport twitter4j.*;%0Aimport com.google.gson.Gson;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.logging.Level;%0A%0A/**%0A * @author Yusuke Yamamoto - yusuke at mac.com%0A * @since Twitter4J 2.1.7%0A */%0Apublic class LatestTweets %7B%0A    /**%0A     * Usage: java twitter4j.examples.search.SearchTweets %5Bquery%5D%0A     *%0A     * @param args search query%0A     */
+%0A%0Apackage model;%0A%0Aimport twitter4j.*;%0Aimport com.google.gson.Gson;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.logging.Level;%0A%0A%0Apublic class LatestTweets %7B%0A   
 %0A   
@@ -366,47 +366,8 @@
     
- // forreturn.append(%22%7B%5C%22trends%5C%22:%5B%22) ;
 %0A   
@@ -447,817 +447,32 @@
     
- //Object etc=new Object();%0A        %0A        %0A       // gl = new GeoLocation(latitude,longitude);%0A        try %7B%0A           // ResponseList tt;%0A           // tt = twitter.getClosestTrends(gl);%0A           // System.out.println(tt.toString());%0A          //  Object value=tt.get(0);%0A            //JSONObject loc;%0A         //  String loc=value.toString().substring(value.toString().indexOf(%22=%22)+1,value.toString().indexOf(%22,%22));%0A            %0A            //loc=gson.fromJson(value,Place).toJson();%0A               //         System.out.println(value.toString());%0A%0A          //  int woeid=1;%0A         //   woeid=Integer.valueOf(loc);%0A         //               System.out.println(%22SearchTweet TEsting Console%22);%0A%0A         //   Trends placeTrends = twitter.getPlaceTrends(woeid);%0A            %0A           // int count=0;
+%0A        try %7B%0A         
 %0A   
@@ -556,40 +556,8 @@
     
- //  etc=gson.toJson(forreturn);
 %0A   
@@ -655,119 +655,8 @@
     
-  //  GeoQuery query = new GeoQuery(new GeoLocation(Double.parseDouble(args%5B0%5D), Double.parseDouble(args%5B1%5D)));
 %0A   
@@ -899,253 +899,74 @@
     
-  // String etc;%0A               %0A                %0A               // System.out.println(etc);%0A                for (Status tweet : tweets) %7B%0A                    //System.out.println(%22@%22 + tweet.getUser().getScreenName() + %22 - %22 + tweet.getText());
+%0A                for (Status tweet : tweets) %7B%0A                   
 %0A   
@@ -1424,35 +1424,8 @@
     
-  // forreturn.append(etc);
 %0A   
@@ -1831,46 +1831,8 @@
     
-    //  System.out.println(forreturn);
 %0A%0Are

Update LatestTweets.java