/** 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 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 ""; }
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); } }
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 TwitterClient(String fileName) throws IOException { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true); TwitterFactory tf = new TwitterFactory(cb.build()); twitter = tf.getInstance(); }
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); } }
@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; }
public Twitter getTwitterInstance(String strAccessToken, String token_secret) { TwitterFactory twitterFactory = new TwitterFactory(getTwitterConfiguration(strAccessToken, token_secret)); Twitter twitterInstance = twitterFactory.getInstance(); return twitterInstance; }
public static Twitter getTwitterInstance() { TwitterFactory factory = new TwitterFactory(); Twitter twitter = factory.getInstance(); twitter.setOAuthConsumer(getConsumerKey(), getConsumerSecret()); return twitter; }
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); }
// 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(); }
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; }
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); }
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; }
/** * 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); }
/** 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(); } } }
@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 initTwitter() { mTwitter = TwitterFactory.getSingleton(); mTwitter.setOAuthConsumer( Configuration.INSTANCE.consumerToken, Configuration.INSTANCE.consumerSecret); mTwitter.setOAuthAccessToken( new AccessToken(Configuration.INSTANCE.accessToken, Configuration.INSTANCE.accessSecret)); }
private static void primeiraTwittada() throws TwitterException, IOException { Twitter twitter = TwitterFactory.getSingleton(); twitter.setOAuthConsumer("HSPokkXFfwsjWwTGy8kfw", "zMNRv0G9kORPiSXcJuPrnWFOBESewPirr8Lf6fRLpA"); 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("GO GO GO"); System.out.println("Successfully updated the status to [" + status.getText() + "]."); System.exit(0); }
@SuppressWarnings("serial") public class FriendsList extends JPanel { private JTextArea FriendsArea; private Twitter twitter = TwitterFactory.getSingleton(); private List<User> friends; public FriendsList() throws TwitterException { new JPanel(); FriendsArea = new JTextArea(); System.out.println("test\n\n"); friends = twitter.getFriendsList(1155288308, -1); System.out.println(friends.size()); for (User user : friends) { // friends2.add(user.getName()); FriendsArea.append(user.getName() + "\n"); } // FollowersPanel.add(FollowersArea); add(FriendsArea); } }
public static void main(String[] args) throws TwitterException, IOException { Twitter twitter = TwitterFactory.getSingleton(); JLanguageTool langTool = new JLanguageTool(new AmericanEnglish()); List<String> twts = new ArrayList<String>(); for (String arg : args) { Query query = new Query(arg); QueryResult result; int counter = 0; do { result = twitter.search(query); List<Status> tweets = result.getTweets(); for (Status tweet : tweets) { if (isEligible(tweet)) { System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText()); System.out.println(tweet.getLang()); twts.add(tweet.getText()); counter++; } } } while ((query = result.nextQuery()) != null && counter < 5); } for (String str : twts) { List<RuleMatch> matches = langTool.check(str); for (RuleMatch match : matches) { System.out.println( "Potential error at line " + match.getLine() + ", column " + match.getColumn() + ": " + match.getMessage()); System.out.println("Suggested correction: " + match.getSuggestedReplacements()); } } }
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)); } }
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(); }
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(); }
public void search() throws TwitterException { Twitter twitter = TwitterFactory.getSingleton(); Query query = new Query("Cruyff"); QueryResult result = twitter.search(query); for (Status status : result.getTweets()) { System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText()); } }
/** * Metodo que permite crear la consulta en tweeter en base al texto ingresado en el query. * * @param textoConsultaEjecutar * @return */ public List<Status> ejecutarQueyEnBaseAConsulta(String textoConsultaEjecutar) { logger.info("<==== armaQueyEnBaseAConsulta ====>"); logger.debug("textoConsultaEjecutar: " + textoConsultaEjecutar); Twitter twitter = TwitterFactory.getSingleton(); Query query = new Query(textoConsultaEjecutar); query.setLang(COD_LENGUAJE_CONSULTA_ESPANOL); return ejecutaQueryEnTwitter(twitter, query); }
public void postTweet(String message) throws TwitterException { Twitter twitter = TwitterFactory.getSingleton(); Status status = null; try { status = twitter.updateStatus(message); } catch (TwitterException te) { System.out.println("Unsuccessfull updated the status"); } System.out.println("Successfully updated the status to [estado]."); }