Package twitter4j

Examples of twitter4j.Twitter


  /*
   * (non-Javadoc)
   * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
   */
  public void start(BundleContext context) throws Exception {
    Twitter twitter = new Twitter();
    Query query = new Query("from:theasf");
   
    try {
      QueryResult result = twitter.search(query);
        List<Tweet> tweets = result.getTweets();
        System.out.println("hits:" + tweets.size());
        for (Tweet tweet : result.getTweets()) {
            System.out.println(tweet.getFromUser() + ":" + StringEscapeUtils.unescapeXml(tweet.getText()));
        }
View Full Code Here


        conf = cb.build();
    }

    public TwitterLoginInformation createLoginInformation(String redirectURL) throws TwitterException {
        Twitter twitter = new TwitterFactory(conf).getInstance();
        String callbackURL = PartakeConfiguration.toppath() + "/auth/verifyForTwitter";
        RequestToken requestToken = twitter.getOAuthRequestToken(callbackURL);

        return new TwitterLoginInformation(twitter, requestToken, redirectURL);
    }
View Full Code Here

        return new TwitterLoginInformation(twitter, requestToken, redirectURL);
    }

    public UserTwitterLink createTwitterLinkageFromLoginInformation(TwitterLoginInformation information, String verifier) throws TwitterException {
        Twitter twitter = information.getTwitter();
        RequestToken requestToken = information.getRequestToken();
        AccessToken accessToken = twitter.getOAuthAccessToken(requestToken, verifier);

        twitter4j.User twitterUser = twitter.showUser(twitter.getId());
        return new UserTwitterLink(
                null, twitter.getId(), null, twitter.getScreenName(), twitterUser.getName(), accessToken.getToken(), accessToken.getTokenSecret(),
                twitter.showUser(twitter.getId()).getProfileImageURL().toString());
    }
View Full Code Here

    }

    @Override
    public void sendDirectMesage(String token, String tokenSecret, long twitterId, String message) throws TwitterException {
        AccessToken accessToken = new AccessToken(token, tokenSecret);
        Twitter twitter = new TwitterFactory(conf).getInstance(accessToken);
        twitter.sendDirectMessage(twitterId, message);
    }
View Full Code Here

    }

    @Override
    public void updateStatus(String token, String tokenSecret, String message) throws TwitterException {
        AccessToken accessToken = new AccessToken(token, tokenSecret);
        Twitter twitter = new TwitterFactory(conf).getInstance(accessToken);
        twitter.updateStatus(message);
    }
View Full Code Here

        List<Resource> twitterResources = findTwitterResources(resourceResolver);

        for (Resource twitterResource : twitterResources) {
            Page page = pageManager.getContainingPage(twitterResource);
            if (page != null) {
                Twitter client = page.adaptTo(Twitter.class);
                if (client != null) {
                    try {
                        ValueMap properties = ResourceUtil.getValueMap(twitterResource);
                        String username = properties.get("username", String.class);

                        if (!StringUtils.isEmpty(username)) {

                            log.info("Loading Twitter timeline for user {} for component {}.", username,
                                    twitterResource.getPath());

                            List<Status> statuses = client.getUserTimeline(username);

                            if (statuses != null) {
                                List<String> tweetsList = new ArrayList<String>(statuses.size());

                                for (Status status : statuses) {
View Full Code Here

        ValueMap oauthProps = ResourceUtil.getValueMap(oauthConfig);
        String consumerKey = oauthProps.get("oauth.client.id", String.class);
        String consumerSecret = oauthProps.get("oauth.client.secret", String.class);

        if (consumerKey != null && consumerSecret != null) {
            Twitter t = factory.getInstance();
            log.debug("Creating client for key {}.", consumerKey);
            t.setOAuthConsumer(consumerKey, consumerSecret);
            try {
                t.getOAuth2Token();
                return new TwitterClientImpl(t, config);
            } catch (TwitterException e) {
                log.error("Unable to create Twitter client.", e);
                return null;
            }
View Full Code Here

  @Test
  public void send() throws TwitterException
  {
     // The factory instance is re-useable and thread safe.
      Twitter twitter = new TwitterFactory().getInstance("geodojo","latinoware");
      Status status = twitter.updateStatus("Testando o  twitter4j");
      System.out.println("Successfully updated the status to [" + status.getText() + "].");
  }
View Full Code Here

   
  }
 
  private void updateTwitter() throws TwitterException
  {
      Twitter twitter = new TwitterFactory().getInstance(this.twitt.getAutor(),this.passwd);
      twitter.updateStatus(this.twitt.getMensagem(),new GeoLocation(this.twitt.getLocation().getY(),this.twitt.getLocation().getX()));   
  }
View Full Code Here

    public static void main(String ... args) throws TwitterException, IOException {
        String consumerKey = "Di1ZjpaZBqBTuCNBMmQ0g";
        String consumerSecret = "Qsa832hZ0z6Di2AY1umfhAgPowf2YtjCxQvooRzXTM";

        Twitter twitter = new TwitterFactory().getInstance();
        twitter.setOAuthConsumer(consumerKey,consumerSecret);
        RequestToken requestToken = twitter.getOAuthRequestToken();
        AccessToken accessToken = null;

        p("go to this url: " + requestToken.getAuthorizationURL());
        p("then press enter");
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String pin = br.readLine();
        if(pin.length() > 0){
            accessToken = twitter.getOAuthAccessToken(requestToken, pin);
        } else {
            accessToken = twitter.getOAuthAccessToken();
        }
        p("got the access token: " + accessToken);
        storeAccessToken(twitter.verifyCredentials().getId() , accessToken);

        AccessToken toke = new AccessToken(accessToken.getToken(), accessToken.getTokenSecret());
        twitter.setOAuthAccessToken(accessToken);
        Status status = twitter.updateStatus("quick test of twitter with oauth. hope this works! :)");
        p("changed the status to : " + status.getText());
    }
View Full Code Here

TOP

Related Classes of twitter4j.Twitter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.