Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Read about Twitter API <a href="https://dev.twitter.com/" rel="nofollow">here</a>, but better library is <a href="http://twitter4j.org/en/index.html" rel="nofollow">Twitter4J</a>. </p> <p>Here you have code samples to :</p> <ul> <li><p>add new tweet :</p> <pre><code>Twitter twitter = TwitterFactory.getSingleton(); Status status = twitter.updateStatus(latestStatus); System.out.println("Successfully updated the status to [" + status.getText() + "]."); </code></pre></li> <li><p>geting timeline :</p> <pre><code> Twitter twitter = TwitterFactory.getSingleton(); List&lt;Status&gt; statuses = twitter.getHomeTimeline(); System.out.println("Showing home timeline."); for (Status status : statuses) { System.out.println(status.getUser().getName() + ":" + status.getText()); } </code></pre></li> <li><p>Log in Twitter using OAuth (code for Java, edit this):</p> <pre><code>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() &gt; 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); </code></pre> <p>}</p> <p>private static void storeAccessToken(int useId, AccessToken accessToken){ //store accessToken.getToken() //store accessToken.getTokenSecret()</p> <ul> <li><p>getting tweets :</p> <pre><code>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()); } </code></pre></li> </ul></li> </ul> <p>I hope I helped.</p> <p>Source : <a href="http://twitter4j.org/en/code-examples.html" rel="nofollow">http://twitter4j.org/en/code-examples.html</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload