问题
I want some resource which can lead me to capture tweets for only a specific links. Suppose i will capture all tweets which contain a link http://aaa.com how can i do it ? thanks
回答1:
Read about Twitter API here, but better library is Twitter4J.
Here you have code samples to :
add new tweet :
Twitter twitter = TwitterFactory.getSingleton(); Status status = twitter.updateStatus(latestStatus); System.out.println("Successfully updated the status to [" + status.getText() + "].");
geting timeline :
Twitter twitter = TwitterFactory.getSingleton(); List<Status> statuses = twitter.getHomeTimeline(); System.out.println("Showing home timeline."); for (Status status : statuses) { System.out.println(status.getUser().getName() + ":" + status.getText()); }
Log in Twitter using OAuth (code for Java, edit this):
Twitter twitter = TwitterFactory.getSingleton(); twitter.setOAuthConsumer("[consumer key]", "[consumer secret]"); RequestToken requestToken = twitter.getOAuthRequestToken(); AccessToken accessToken = null; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (null == accessToken) { System.out.println("Open the following URL and grant access to your account:"); System.out.println(requestToken.getAuthorizationURL()); System.out.print("Enter the PIN(if aviailable) or just hit enter.[PIN]:"); String pin = br.readLine(); try{ if(pin.length() > 0){ accessToken = twitter.getOAuthAccessToken(requestToken, pin); }else{ accessToken = twitter.getOAuthAccessToken(); } } catch (TwitterException te) { if(401 == te.getStatusCode()){ System.out.println("Unable to get the access token."); }else{ te.printStackTrace(); } } } //persist to the accessToken for future reference. storeAccessToken(twitter.verifyCredentials().getId() , accessToken); Status status = twitter.updateStatus(args[0]); System.out.println("Successfully updated the status to [" + status.getText() + "]."); System.exit(0);
}
private static void storeAccessToken(int useId, AccessToken accessToken){ //store accessToken.getToken() //store accessToken.getTokenSecret()
getting tweets :
Twitter twitter = TwitterFactory.getSingleton(); Query query = new Query("source:twitter4j yusukey"); QueryResult result = twitter.search(query); for (Status status : result.getStatuses()) { System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText()); }
I hope I helped.
Source : http://twitter4j.org/en/code-examples.html
回答2:
Take a look into the Twitter API. https://dev.twitter.com/
As it is, this question is a bit too open-ended to be answered easily. In essence, you're going to be using the API to pull a given tweet, then using some of your own code to parse for the URL you want to check, and then finally doing something with the URL or tweet.
Please do a bit of research and come back with a more specific question.
来源:https://stackoverflow.com/questions/14564805/how-can-i-get-a-tweet-for-a-specific-url