Package twitter4j

Examples of twitter4j.Twitter


     * Verify Credentials.
     * @param socialAccount
     * @return
     */
    public Boolean verifyCredentials(){
        final Twitter twitter = this.getTwitterInstance();
        User user;
        try {
            user = twitter.verifyCredentials();
        } catch (TwitterException e) {
            user = null;
            log.error(e);
        }
        return user == null ? false : true;
View Full Code Here


     * @param socialTwitterAccount {@link SocialAccount}.
     * @return {@link Twitter}.
     */
    private Twitter getOAuthAuthorizedInstance(){
        final TwitterFactory tf = new TwitterFactory(this.configurationBuilder.build());
        final Twitter twitter = tf.getInstance();
        return twitter;
    }
View Full Code Here

            throw new IllegalArgumentException("Consumer key is missing");
        }
        if (consumerSecret == null) {
            throw new IllegalArgumentException("Consumer secret is missing");
        }
        final Twitter twitter = new TwitterFactory().getInstance();
        twitter.setOAuthConsumer(consumerKey, consumerSecret);
        return twitter.getOAuthRequestToken();
    }
View Full Code Here

    }

    @Override
    public AuthRequest getAuthUrl(ClientSessionModel clientSession, SocialProviderConfig config, String state) throws SocialProviderException {
        try {
            Twitter twitter = new TwitterFactory().getInstance();
            twitter.setOAuthConsumer(config.getKey(), config.getSecret());

            URI uri = new URI(config.getCallbackUrl() + "?state=" + state);

            RequestToken requestToken = twitter.getOAuthRequestToken(uri.toString());
            clientSession.setNote("twitter_token", requestToken.getToken());
            clientSession.setNote("twitter_tokenSecret", requestToken.getTokenSecret());
            return AuthRequest.create(requestToken.getAuthenticationURL())
                    .build();
        } catch (Exception e) {
View Full Code Here

        if (callback.getQueryParam("denied") != null) {
            throw new SocialAccessDeniedException();
        }

        try {
            Twitter twitter = new TwitterFactory().getInstance();
            twitter.setOAuthConsumer(config.getKey(), config.getSecret());

            String token = callback.getQueryParam("oauth_token");
            String verifier = callback.getQueryParam("oauth_verifier");
            String twitterToken = clientSession.getNote("twitter_token");
            String twitterSecret = clientSession.getNote("twitter_tokenSecret");

            RequestToken requestToken = new RequestToken(twitterToken, twitterSecret);

            twitter.getOAuthAccessToken(requestToken, verifier);
            twitter4j.User twitterUser = twitter.verifyCredentials();

            SocialUser user = new SocialUser(Long.toString(twitterUser.getId()), twitterUser.getScreenName());
            user.setName(twitterUser.getName());

            return user;
View Full Code Here

            numberOfPages = te.getProperties().getNumberOfPages();
        }
       
        LOG.debug("Searching with " + numberOfPages + " pages.");

        Twitter twitter = te.getProperties().getTwitter();
        QueryResult qr = twitter.search(query);
        List<Status> tweets = qr.getTweets();

        for (int i = 1; i < numberOfPages; i++) {
            if (!qr.hasNext()) {
                break;
            }

            qr = twitter.search(qr.nextQuery());
            tweets.addAll(qr.getTweets());
        }

        if (te.getProperties().isFilterOld()) {
            for (Status t : tweets) {
View Full Code Here

        AccessToken accessToken = new AccessToken(
                settings.get("river.twitter.oauth.access_token"),
                settings.get("river.twitter.oauth.access_token_secret"));


        Twitter twitter = new TwitterFactory().getInstance();
        twitter.setOAuthConsumer(
                settings.get("river.twitter.oauth.consumer_key"),
                settings.get("river.twitter.oauth.consumer_secret"));
        twitter.setOAuthAccessToken(accessToken);

        Status status = twitter.updateStatus("testing twitter river. Please ignore. " +
                        DateTime.now().toString());
        logger.info("  -> tweet [{}] sent: [{}]", status.getId(), status.getText());

        assertThat(awaitBusy(new Predicate<Object>() {
            public boolean apply(Object obj) {
View Full Code Here

  public static void main(String args[]) throws Exception {
    String oAuthConsumerKey = args[0];
    String oAuthConsumerSecret = args[1];

    // The factory instance is re-useable and thread safe.
    Twitter twitter = new TwitterFactory().getInstance();
    twitter.setOAuthConsumer(oAuthConsumerKey, oAuthConsumerSecret);
    RequestToken requestToken = twitter.getOAuthRequestToken("oob");
    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);
  }
View Full Code Here

        builder.setOAuthAccessTokenSecret(token.getSecret());
        Configuration conf = builder.build();

        Authorization authorization = AuthorizationFactory
            .getInstance(conf);
        Twitter twitter = new TwitterFactory()
            .getInstance(authorization);
        keyTwitters.add(twitter);
      }
      twitters.put(key, keyTwitters);
      mentions.put(key, new TreeSet<Status>());
View Full Code Here

      .getName());

  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws IOException {

    Twitter twitter = new TwitterFactory().getInstance();
    // get auth info from system properties
    String key = AuthenticationProvider.getProp("twitter-consumer-key");
    String secret = AuthenticationProvider.getProp("twitter-consumer-secret");
   
    if(key == null || secret == null){
      response.setContentType("text/html");
      response.getWriter().print(AppLib.INFONOTFOUND);
      return;
    }

    try {
      twitter.setOAuthConsumer(key, secret);
      String callbackURL = buildCallBackURL(request, AuthenticationProvider.TWITTER);
      RequestToken token = twitter.getOAuthRequestToken(callbackURL);
      request.getSession().setAttribute("requestToken", token);
      String loginURL = token.getAuthenticationURL() + "&force_login=true";
      log.info("Redirecting to: " + loginURL);
      response.sendRedirect(loginURL);
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.