public RequestToken getRequestToken(String type) {
    if (requestToken == null) {
      Log.d("===", "requestToken = NULL ");
      try {
        if (type.equals("PIC")) {
          Log.d("===", "PIC");
          requestToken =
              twitterFactory
                  .getInstance()
                  .getOAuthRequestToken(ConstantValues.TWITTER_CALLBACK_URL_PIC);
          Log.d("===", "requestToken.getToken() = " + requestToken.getToken());
          Log.d("===", "requestToken.getTokenSecret: " + requestToken.getTokenSecret());
        } else {
          requestToken =
              twitterFactory
                  .getInstance()
                  .getOAuthRequestToken(ConstantValues.TWITTER_CALLBACK_URL_VIDEO);
        }

      } catch (TwitterException e) {
        e
            .printStackTrace(); // To change body of catch statement use File | Settings | File
                                // Templates.
      }
    }
    return requestToken;
  }
  public static void main(String args[]) {
    try {
      ConfigurationBuilder cb = new ConfigurationBuilder();
      cb.setDebugEnabled(true)
          .setOAuthConsumerKey(cK)
          .setOAuthConsumerSecret(cS)
          .setOAuthAccessToken(aT)
          .setOAuthAccessTokenSecret(aTS);

      TwitterFactory tf = new TwitterFactory(cb.build());
      Twitter twitter = tf.getInstance();
      long cursor = -1;
      long IDS = 2458351900L;
      IDs ids;
      System.out.println("Listing followers's ids.");
      do {
        ids = twitter.getFollowersIDs(IDS, cursor);

        for (long id : ids.getIDs()) {
          System.out.println(id);
        }
      } while ((cursor = ids.getNextCursor()) != 0);
      System.exit(0);
    } catch (TwitterException te) {
      te.printStackTrace();
      System.out.println("Failed to get followers' ids: " + te.getMessage());
      System.exit(-1);
    }
  }
  public TwitterClient(String fileName) throws IOException {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);

    TwitterFactory tf = new TwitterFactory(cb.build());
    twitter = tf.getInstance();
  }
  public String twitterLogin() {
    ConfigurationBuilder cb = new ConfigurationBuilder();

    cb.setDebugEnabled(true)
        .setOAuthConsumerKey(BUNDLE.getString("twt.client_id"))
        .setOAuthConsumerSecret(BUNDLE.getString("twt.secret"))
        .setOAuthRequestTokenURL("https://api.twitter.com/oauth/request_token")
        .setOAuthAuthorizationURL(("https://api.twitter.com/oauth/authorize"))
        .setOAuthAccessTokenURL(("https://api.twitter.com/oauth/access_token"));
    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();
    HttpServletRequest request =
        (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
    HttpServletResponse response =
        (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
    request.getSession().setAttribute("twitter", twitter);
    try {
      RequestToken requestToken =
          twitter.getOAuthRequestToken(BUNDLE.getString("twt.redirect_uri"));
      request.getSession().setAttribute("requestToken", requestToken);
      LOGGER.info("requestToken.getAuthenticationURL():" + requestToken.getAuthenticationURL());
      try {
        response.sendRedirect(requestToken.getAuthenticationURL());
      } catch (IOException e) {
        e.printStackTrace();
      }

    } catch (TwitterException e) {
      e.printStackTrace();
    }
    return "";
  }
  @Override
  public String input() throws Exception {

    if (!isEmpty(denied)) {
      // todo: inform user that authorization has been denied
      return SUCCESS;
    }

    TwitterFactory tf = new TwitterFactory(TwitterConfigFactory.getConfig());
    Twitter twitter = tf.getInstance();

    RequestToken requestToken = (RequestToken) session.get("requestToken");

    AccessToken accessToken = twitter.getOAuthAccessToken(requestToken, oauthVerifier);

    try (GroupTwitterCredentialsDao groupTwitterCredentialsDao =
        new DbiFactory().getDbi().open(GroupTwitterCredentialsDao.class)) {
      groupTwitterCredentialsDao.createGroupTwitterCredentials(
          groupId,
          accessToken.getScreenName(),
          accessToken.getUserId(),
          accessToken.getToken(),
          accessToken.getTokenSecret());
    }

    // todo: inform user that authorization was successful
    return SUCCESS;
  }
  private void loginToTwitter() {
    boolean isLoggedIn = mSharedPreferences.getBoolean(PREF_KEY_TWITTER_LOGIN, false);

    if (!isLoggedIn) {
      final ConfigurationBuilder builder = new ConfigurationBuilder();
      builder.setOAuthConsumerKey(consumerKey);
      builder.setOAuthConsumerSecret(consumerSecret);

      final Configuration configuration = builder.build();
      final TwitterFactory factory = new TwitterFactory(configuration);
      twitter = factory.getInstance();

      try {
        requestToken = twitter.getOAuthRequestToken(callbackUrl);

        /**
         * Loading twitter login page on webview for authorization Once authorized, results are
         * received at onActivityResult
         */
        final Intent intent = new Intent(this, WebViewActivity.class);
        intent.putExtra(WebViewActivity.EXTRA_URL, requestToken.getAuthenticationURL());
        startActivityForResult(intent, WEBVIEW_REQUEST_CODE);

      } catch (TwitterException e) {
        e.printStackTrace();
      }
    } else {
      Intent intent = new Intent(MainActivity.this, MenuActivity.class);
      startActivity(intent);
    }
  }
  /** Function to login twitter */
  private void loginToTwitter() {
    // Check if already logged in
    if (!isTwitterLoggedInAlready()) {
      ConfigurationBuilder builder = new ConfigurationBuilder();
      builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
      builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
      twitter4j.conf.Configuration configuration = builder.build();

      TwitterFactory factory = new TwitterFactory(configuration);
      twitter = factory.getInstance();

      Thread thread =
          new Thread(
              new Runnable() {
                @Override
                public void run() {
                  try {

                    requestToken = twitter.getOAuthRequestToken(TWITTER_CALLBACK_URL);
                    Login_Activity.this.startActivity(
                        new Intent(
                            Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL())));
                  } catch (Exception e) {
                    e.printStackTrace();
                  }
                }
              });
      thread.start();

    } else {
      // user already logged into twitter
      Toast.makeText(context, "already logged in 2222", Toast.LENGTH_SHORT).show();
    }
  }
  public static Twitter getTwitterInstance() {

    TwitterFactory factory = new TwitterFactory();
    Twitter twitter = factory.getInstance();
    twitter.setOAuthConsumer(getConsumerKey(), getConsumerSecret());

    return twitter;
  }
 public TwitterUtil() {
   ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
   configurationBuilder.setOAuthConsumerKey(ConstantValues.TWITTER_CONSUMER_KEY);
   configurationBuilder.setOAuthConsumerSecret(ConstantValues.TWITTER_CONSUMER_SECRET);
   Configuration configuration = configurationBuilder.build();
   twitterFactory = new TwitterFactory(configuration);
   twitter = twitterFactory.getInstance();
 }
  private void initTwitterClient() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(mConsumerKey);
    builder.setOAuthConsumerSecret(mConsumerSecret);

    String accessToken = mSharedPreferences.getString(SAVE_STATE_KEY_OAUTH_TOKEN, null);
    String accessTokenSecret = mSharedPreferences.getString(SAVE_STATE_KEY_OAUTH_SECRET, null);

    TwitterFactory factory = new TwitterFactory(builder.build());

    if (TextUtils.isEmpty(accessToken) && TextUtils.isEmpty(accessTokenSecret)) {
      mTwitter = factory.getInstance();
    } else {
      mTwitter =
          factory.getInstance(new twitter4j.auth.AccessToken(accessToken, accessTokenSecret));
    }
  }
  public Twitter getTwitterInstance(String strAccessToken, String token_secret) {

    TwitterFactory twitterFactory =
        new TwitterFactory(getTwitterConfiguration(strAccessToken, token_secret));
    Twitter twitterInstance = twitterFactory.getInstance();

    return twitterInstance;
  }
 // Initialize the config of the builder with the user credentials
 public void initConfig() {
   ConfigurationBuilder cb = new ConfigurationBuilder();
   cb.setDebugEnabled(true)
       .setOAuthConsumerKey(AppliSettings.consumerKey)
       .setOAuthConsumerSecret(AppliSettings.consumerSecret)
       .setOAuthAccessToken(AppliSettings.accessToken)
       .setOAuthAccessTokenSecret(AppliSettings.accessTokenSecret);
   TwitterFactory tf = new TwitterFactory(cb.build());
   InterfaceG.twitter = tf.getInstance();
 }
Exemple #13
0
 private static void twittarAlgo() throws TwitterException {
   TwitterFactory factory = new TwitterFactory();
   AccessToken accessToken = loadAccessToken();
   Twitter twitter = factory.getInstance();
   twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
   twitter.setOAuthAccessToken(accessToken);
   Status status = twitter.updateStatus("go go go go");
   System.out.println("Successfully updated the status to [" + status.getText() + "].");
   System.exit(0);
 }
Exemple #14
0
  public Twitter getTwitterProxy() throws TwitterException {
    if (twitter == null) {

      TwitterFactory tf = new TwitterFactory();
      twitter = tf.getInstance();

      twitter.setOAuthConsumer(getConsumerKey(), getConsumerSecret());
      twitter.setOAuthAccessToken(new AccessToken(getAccessToken(), getAccessTokenSecret()));
    }
    return twitter;
  }
Exemple #15
0
 private static List<Status> buscarTag(String tag) throws TwitterException {
   TwitterFactory factory = new TwitterFactory();
   AccessToken accessToken = loadAccessToken();
   Twitter twitter = factory.getInstance();
   twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
   twitter.setOAuthAccessToken(accessToken);
   Query query = new Query(tag);
   query.setCount(100);
   QueryResult result = twitter.search(query);
   // printResultadosConsulta(result);
   return result.getTweets();
 }
  /**
   * Twitter Post
   *
   * @param userModel
   * @param msg
   * @return
   */
  private void postMessage(UserModel userModel, String msg) throws Exception {

    System.out.println(msg);

    // 承認情報の生成
    ConfigurationBuilder cb = getConfigurationBuilder(userModel);

    // Titterオブジェクトの生成
    TwitterFactory twitterFactory = new TwitterFactory(cb.build());
    Twitter twitter = twitterFactory.getInstance();

    twitter.updateStatus(msg);
  }
Exemple #17
0
 public Twitter getTwitterInstance() {
   if (twitterInstance == null) {
     ConfigurationBuilder cb = new ConfigurationBuilder();
     cb.setDebugEnabled(true) // TODO disable logging for production
         .setOAuthConsumerKey(TWITTER_KEY)
         .setOAuthConsumerSecret(TWITTER_SECRET)
         .setOAuthAccessToken(accessToken)
         .setOAuthAccessTokenSecret(accessTokenSecret);
     TwitterFactory tf = new TwitterFactory(cb.build());
     twitterInstance = tf.getInstance();
   }
   return twitterInstance;
 }
  @Override
  public Maybe<UserRef> check(AuthToken authToken) {
    Preconditions.checkArgument(authToken.isFor(UserNamespace.TWITTER));

    AccessToken token = new AccessToken(authToken.tokenPayload(), authToken.secretPayload());
    Twitter twitter = twitterFactory.getInstance(token);
    try {
      return Maybe.just(
          userRefBuilder.from(String.valueOf(twitter.getId()), UserNamespace.TWITTER));
    } catch (TwitterException e) {
      return Maybe.nothing();
    }
  }
 /**
  * Set the proxy configuration for the univ or not
  *
  * @param checked : boolean sent by the controller
  */
 public void setProxy(boolean checked) throws IOException {
   if (checked) {
     ConfigurationBuilder cb = new ConfigurationBuilder();
     cb.setDebugEnabled(true)
         .setOAuthConsumerKey(AppliSettings.consumerKey)
         .setOAuthConsumerSecret(AppliSettings.consumerSecret)
         .setOAuthAccessToken(AppliSettings.accessToken)
         .setOAuthAccessTokenSecret(AppliSettings.accessTokenSecret)
         .setHttpProxyHost(AppliSettings.proxy)
         .setHttpProxyPort(AppliSettings.port);
     TwitterFactory tf = new TwitterFactory(cb.build());
     InterfaceG.twitter = tf.getInstance();
   }
 }
  // 6355366
  private static void testTwitterAPI() throws Exception {

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true)
        .setOAuthConsumerKey("qHzxaFrfzktB7DonlQXLzQ")
        .setOAuthConsumerSecret("WTcdE2vN9U3nl3t6mQkUbfF4PNNey2t2dp78AEajp8")
        .setOAuthAccessToken("351435596-KpFoMU2mdiu5OhdBi0BRPpdd7bQgkJFakkTV6Zh6")
        .setOAuthAccessTokenSecret("80OjYaYPmmKYG6DAUCSfstJEMPl2UnnLJunF8r0GGXQ");
    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();
    // DirectMessage msg = twitter.sendDirectMessage("prakash_sandeep", "test direct message1.");
    Status status = twitter.updateStatus("This is a test message13.");
    // System.out.println(msg + " published a message.");
  }
  public void testFactoryInstantiation() throws Exception {
    TwitterFactory twitterFactory = (TwitterFactory) beanFactory.getBean("twitterFactory");
    Twitter twitter = twitterFactory.getInstance();
    assertTrue(twitter instanceof Twitter);

    AsyncTwitterFactory asyncTwitterFactory =
        (AsyncTwitterFactory) beanFactory.getBean("asyncTwitterFactory");
    AsyncTwitter asyncTwitter = asyncTwitterFactory.getInstance();
    assertTrue(asyncTwitter instanceof AsyncTwitter);

    TwitterStreamFactory twitterStreamFactory =
        (TwitterStreamFactory) beanFactory.getBean("twitterStreamFactory");
    TwitterStream twitterStream = twitterStreamFactory.getInstance("test", "test");
    assertTrue(twitterStream instanceof TwitterStream);
  }
Exemple #22
0
  /** Function to login twitter */
  private void loginToTwitter() {
    // Check if already logged in
    if (!isTwitterLoggedInAlready()) {
      ConfigurationBuilder builder = new ConfigurationBuilder();
      builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
      builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
      Configuration configuration = builder.build();

      TwitterFactory factory = new TwitterFactory(configuration);
      twitter = factory.getInstance();

      try {
        requestToken = twitter.getOAuthRequestToken(TWITTER_CALLBACK_URL);
        this.startActivity(
            new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL())));

        String status = txtUpdate.getText().toString();

        // Check for blank text
        if (status.trim().length() > 0) {
          // update status
          new updateTwitterStatus().execute(status);
        } else {
          // EditText is empty
          Toast.makeText(getApplicationContext(), "Please enter status message", Toast.LENGTH_SHORT)
              .show();
        }
      } catch (TwitterException e) {
        e.printStackTrace();
      }
    } else {
      // user already logged into twitter
      /*Toast.makeText(getApplicationContext(),
      "Already Logged into twitter", Toast.LENGTH_LONG).show();*/

      String status = txtUpdate.getText().toString();

      // Check for blank text
      if (status.trim().length() > 0) {
        // update status
        new updateTwitterStatus().execute(status);
      } else {
        // EditText is empty
        Toast.makeText(getApplicationContext(), "Please enter status message", Toast.LENGTH_SHORT)
            .show();
      }
    }
  }
Exemple #23
0
  @Override
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    response.setContentType("text/plain");

    TwitterFactory factory = new TwitterFactory();
    Twitter twitter = factory.getInstance();
    try {
      twitter.updateStatus("テスト");
      response.getWriter().println("OK");
    } catch (TwitterException e) {
      e.printStackTrace();
      response.getWriter().println(e.getMessage());
    }
  }
  private void loginWithTwitterWeb() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(Constants.TWITTER_CONSUMER_KEY);
    builder.setOAuthConsumerSecret(Constants.TWITTER_CONSUMER_SECRET);
    twitter4j.conf.Configuration configuration = builder.build();

    TwitterFactory factory = new TwitterFactory(configuration);
    twitter = factory.getInstance();

    CookieSyncManager.createInstance(mContext);
    CookieManager cookiemanager = CookieManager.getInstance();
    cookiemanager.removeSessionCookie();
    twitter.setOAuthAccessToken(null);

    mTwitterWebDialog = new WebDialog(mContext, twitter);
    mTwitterWebDialog.show();
  }
  @Override
  public void requestToken() {
    ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
    Configuration configuration =
        configurationBuilder
            .setOAuthConsumerKey(CONSUMER_KEY)
            .setOAuthConsumerSecret(CONSUMER_SECRET)
            .build();

    TwitterFactory twitterFactory = new TwitterFactory(configuration);
    twitter = twitterFactory.getInstance();

    // TODO:
    try {
      requestToken = twitter.getOAuthRequestToken(CALLBACK_URL);
    } catch (TwitterException e) {
      e.printStackTrace();
    }
  }
Exemple #26
0
  public void configureNeedingPersistence(PlatformConfiguration pc) {

    try {
      // Twitter twitter = TwitterFactory.getSingleton();
      ConfigurationBuilder cb = new ConfigurationBuilder();
      cb.setUseSSL(true);
      cb.setOAuthConsumerKey(TwitterUtilities.getApiKey())
          .setOAuthConsumerSecret(TwitterUtilities.getApiKeySecret());
      TwitterFactory tf = new TwitterFactory(cb.build());
      twitter = tf.getInstance();
    } catch (Throwable t) {
      Tracer.platformLogger.error("TwitterBaseImpl.setOAuthConsumer ", t);
    }

    /*try {
      MpJobsLauncher.launch("system");
    } catch (Exception e) {
      Tracer.logExceptionOnPlatformOrOther(e);
    } */

  }
  private static Twitter getTwitter(HandlerContext handlerContext) {
    Twitter res = (Twitter) handlerContext.get("twitter");
    if (res == null) {
      TwitterLinksHandlerConfig twitterLinksHandlerConfig =
          (TwitterLinksHandlerConfig) handlerContext.getHandlerConfig();
      ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
      configurationBuilder
          .setDebugEnabled(true)
          .setOAuthConsumerKey(twitterLinksHandlerConfig.getOauthConsumerKey());
      configurationBuilder.setOAuthConsumerSecret(
          twitterLinksHandlerConfig.getOauthConsumerSecret());
      configurationBuilder.setOAuthAccessToken(twitterLinksHandlerConfig.getOauthAccessToken());
      configurationBuilder.setOAuthAccessTokenSecret(
          twitterLinksHandlerConfig.getOauthAccessTokenSecret());
      TwitterFactory twitterFactory = new TwitterFactory(configurationBuilder.build());
      res = twitterFactory.getInstance();

      handlerContext.put("twitter", res);
    }
    return res;
  }
  /** Function to login twitter */
  private void loginToTwitter() {
    Log.d(TAG, "loginToTwitter!");
    // Check if already logged in
    if (!isTwitterLoggedInAlready()) {
      Log.d(TAG, "no already logged!");
      // Check is we already have tokens
      boolean already_have_tokens = already_have_twitter_tokens();
      if (already_have_tokens == true) {
        Log.d(TAG, "Already have twitter tokens -> Log in!");
        Intent i = new Intent(LoginActivity.this, MainActivity.class);
        startActivityForResult(i, REQUEST_CODE_TWITTER_LOGIN);
      } else {
        Log.d(TAG, "Starting twitter external auth!");

        ConfigurationBuilder builder = new ConfigurationBuilder();
        builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
        builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
        Configuration configuration = builder.build();

        TwitterFactory factory = new TwitterFactory(configuration);
        twitter = factory.getInstance();

        try {
          requestToken = twitter.getOAuthRequestToken(TWITTER_CALLBACK_URL);
          this.startActivity(
              new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL())));
        } catch (TwitterException e) {
          e.printStackTrace();
        }
      }
    } else {
      // user already logged into twitter
      Log.d(TAG, "Already Logged into twitter");

      Intent i = new Intent(LoginActivity.this, MainActivity.class);
      startActivityForResult(i, REQUEST_CODE_TWITTER_LOGIN);
    }
  }
    @Override
    protected Void doInBackground(Void... params) {
      // Check if already logged in
      if (!isTwitterLoggedInAlready()) {
        ConfigurationBuilder builder = new ConfigurationBuilder();
        builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
        builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
        Configuration configuration = builder.build();

        TwitterFactory factory = new TwitterFactory(configuration);
        twitter = factory.getInstance();

        try {
          requestToken = twitter.getOAuthRequestToken(TWITTER_CALLBACK_URL);

          LoginActivity.this.startActivity(
              new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL())));

        } catch (TwitterException e) {
          e.printStackTrace();
        }
      }
      return null;
    }
 /** Function to login twitter */
 private void loginToTwitter() {
   // Check if already logged in
   if (!isTwitterLoggedInAlready()) {
     ConfigurationBuilder builder = new ConfigurationBuilder();
     builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
     builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
     Configuration configuration = builder.build();
     TwitterFactory factory = new TwitterFactory(configuration);
     twitter = factory.getInstance();
     try {
       requestToken = twitter.getOAuthRequestToken(TWITTER_CALLBACK_URL);
       this.startActivity(
           new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL())));
     } catch (TwitterException e) {
       e.printStackTrace();
     }
   } else {
     // user already logged into twitter
     Toast toast =
         Toast.makeText(MainActivity.this, "Already Logged into twitter", Toast.LENGTH_LONG);
     toast.setGravity(Gravity.CENTER, 0, 0);
     toast.show();
   }
 }