List of usage examples for twitter4j.conf ConfigurationBuilder setOAuthConsumerSecret
public ConfigurationBuilder setOAuthConsumerSecret(String oAuthConsumerSecret)
From source file:com.irontec.mintzatu.EzarpenakDetailActivity.java
private void askOAuth() { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setOAuthConsumerKey(TwitterHelper.CONSUMER_KEY); configurationBuilder.setOAuthConsumerSecret(TwitterHelper.CONSUMER_SECRET); Configuration configuration = configurationBuilder.build(); twitter = new TwitterFactory(configuration).getInstance(); try {/*from ww w. ja v a2 s . co m*/ requestToken = twitter.getOAuthRequestToken(TwitterHelper.CALLBACK_URL); Intent i = new Intent(this, WebviewActivity.class); i.putExtra("URL", requestToken.getAuthenticationURL()); startActivityForResult(i, TWITTER_AUTH); } catch (TwitterException e) { e.printStackTrace(); } }
From source file:com.javielinux.api.loaders.ImageUploadLoader.java
License:Apache License
@Override public BaseResponse loadInBackground() { try {//from w w w . j a va 2s . c o m ImageUploadResponse response = new ImageUploadResponse(); String f = Utils.appUploadImageDirectory + request.getFilename(); response.setFile(request.getFilename()); /* int size = Integer.parseInt(Utils.getPreference(mContext).getString("prf_size_photo", "2")); if (size == 1) { Bitmap resizedBitmap = Utils.getResizeBitmapFromFile(f, Utils.HEIGHT_PHOTO_SIZE_SMALL); if (resizedBitmap!=null) { FileOutputStream out = new FileOutputStream(f); resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 95, out); } } else if (size == 2) { Bitmap resizedBitmap = Utils.getResizeBitmapFromFile(f, Utils.HEIGHT_PHOTO_SIZE_MIDDLE); if (resizedBitmap!=null) { FileOutputStream out = new FileOutputStream(f); resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 95, out); } } */ response.setBmp(ImageUtils.getBitmapFromFile(f, Utils.HEIGHT_THUMB_NEWSTATUS, true)); File file = new File(f); int type = Integer.parseInt(Utils.getPreference(getContext()).getString("prf_service_image", "1")); MediaProvider mp = MediaProvider.YFROG; if (type == 1) { mp = MediaProvider.YFROG; } else if (type == 2) { mp = MediaProvider.TWITPIC; } else if (type == 3) { mp = MediaProvider.PLIXI; } loadConsumerKeys(); ConfigurationBuilder confBuild = new ConfigurationBuilder(); confBuild.setOAuthConsumerKey(consumerKey); confBuild.setOAuthConsumerSecret(consumerSecretKey); confBuild.setOAuthAccessToken(ConnectionManager.getInstance().getTwitter(request.getUserId()) .getOAuthAccessToken().getToken()); confBuild.setOAuthAccessTokenSecret(ConnectionManager.getInstance().getTwitter(request.getUserId()) .getOAuthAccessToken().getTokenSecret()); if (type == 1) { } else if (type == 2) { confBuild.setMediaProviderAPIKey("e3533af853e8f63a0018a2c63d7ee69f"); } else if (type == 3) { confBuild.setMediaProviderAPIKey("57438faa-51e4-43a5-9e15-0c63b6f73950"); } confBuild.setMediaProvider(mp.name()); Configuration config = confBuild.build(); ImageUpload upload = new ImageUploadFactory(config).getInstance(mp); if (upload != null) { response.setUrl(upload.upload(file)); return response; } else { ErrorResponse errorResponse = new ErrorResponse(); errorResponse.setError("Image upload is null"); return errorResponse; } } catch (TwitterException exception) { exception.printStackTrace(); ErrorResponse errorResponse = new ErrorResponse(); errorResponse.setError(exception, exception.getMessage()); return errorResponse; } catch (Exception exception) { exception.printStackTrace(); ErrorResponse errorResponse = new ErrorResponse(); errorResponse.setError(exception, exception.getMessage()); return errorResponse; } }
From source file:com.javielinux.task.ImageUploadAsyncTask.java
License:Apache License
@Override protected ImageUploadAsyncTask.ImageUploadResult doInBackground(String... args) { ImageUploadResult iur = new ImageUploadResult(); try {//from w w w. j ava 2 s .c om String f = Utils.appUploadImageDirectory + args[0]; iur.file = args[0]; /* int size = Integer.parseInt(Utils.getPreference(mContext).getString("prf_size_photo", "2")); if (size == 1) { Bitmap resizedBitmap = Utils.getResizeBitmapFromFile(f, Utils.HEIGHT_PHOTO_SIZE_SMALL); if (resizedBitmap!=null) { FileOutputStream out = new FileOutputStream(f); resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 95, out); } } else if (size == 2) { Bitmap resizedBitmap = Utils.getResizeBitmapFromFile(f, Utils.HEIGHT_PHOTO_SIZE_MIDDLE); if (resizedBitmap!=null) { FileOutputStream out = new FileOutputStream(f); resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 95, out); } } */ iur.bmp = ImageUtils.getBitmapFromFile(f, Utils.HEIGHT_THUMB_NEWSTATUS, true); File file = new File(f); int type = Integer.parseInt(Utils.getPreference(mContext).getString("prf_service_image", "1")); MediaProvider mp = MediaProvider.YFROG; if (type == 1) { mp = MediaProvider.YFROG; } else if (type == 2) { mp = MediaProvider.TWITPIC; } else if (type == 3) { mp = MediaProvider.PLIXI; } loadConsumerKeys(); ConfigurationBuilder confBuild = new ConfigurationBuilder(); confBuild.setOAuthConsumerKey(consumerKey); confBuild.setOAuthConsumerSecret(consumerSecretKey); confBuild.setOAuthAccessToken(twitter.getOAuthAccessToken().getToken()); confBuild.setOAuthAccessTokenSecret(twitter.getOAuthAccessToken().getTokenSecret()); if (type == 1) { } else if (type == 2) { confBuild.setMediaProviderAPIKey("e3533af853e8f63a0018a2c63d7ee69f"); } else if (type == 3) { confBuild.setMediaProviderAPIKey("57438faa-51e4-43a5-9e15-0c63b6f73950"); } confBuild.setMediaProvider(mp.name()); Configuration config = confBuild.build(); ImageUpload upload = new ImageUploadFactory(config).getInstance(mp); if (upload != null) { iur.url = upload.upload(file); iur.error = false; } else { iur.error = true; } } catch (TwitterException e) { e.printStackTrace(); iur.error = true; } catch (Exception e) { e.printStackTrace(); iur.error = true; } return iur; }
From source file:com.javielinux.twitter.ConnectionManager.java
License:Apache License
public Configuration getConfiguration() { NetworkConfig config = getNetworkConfig(); ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setOAuthConsumerKey(config.getConsumerKey()); configurationBuilder.setOAuthConsumerSecret(config.getConsumerSecret()); configurationBuilder.setUseSSL(true); return configurationBuilder.build(); }
From source file:com.klinker.android.twitter.activities.setup.LoginActivity.java
License:Apache License
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences", 0); context = this; settings = AppSettings.getInstance(context); //context.sendBroadcast(new Intent("com.klinker.android.twitter.STOP_PUSH")); Utils.setUpTheme(context, settings); setContentView(R.layout.login_activity); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(settings.TWITTER_CONSUMER_KEY); builder.setOAuthConsumerSecret(settings.TWITTER_CONSUMER_SECRET); Configuration configuration = builder.build(); TwitterFactory factory = new TwitterFactory(configuration); twitter = factory.getInstance();//from ww w . j av a 2 s . c o m btnLoginTwitter = (Button) findViewById(R.id.btnLoginTwitter); noThanks = (Button) findViewById(R.id.dont_follow); title = (TextSwitcher) findViewById(R.id.welcome); summary = (TextSwitcher) findViewById(R.id.info); progDescription = (TextSwitcher) findViewById(R.id.progress_desc); progressBar = (ProgressBar) findViewById(R.id.progress_bar); main = (LinearLayout) findViewById(R.id.mainLayout); Animation in = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left); Animation out = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right); title.setFactory(new ViewSwitcher.ViewFactory() { public View makeView() { TextView myText = new TextView(LoginActivity.this); myText.setTextSize(30); return myText; } }); // set the animation type of textSwitcher title.setInAnimation(in); title.setOutAnimation(out); summary.setFactory(new ViewSwitcher.ViewFactory() { public View makeView() { TextView myText = new TextView(LoginActivity.this); myText.setTextSize(17); return myText; } }); // set the animation type of textSwitcher summary.setInAnimation(in); summary.setOutAnimation(out); progDescription.setFactory(new ViewSwitcher.ViewFactory() { public View makeView() { TextView myText = new TextView(LoginActivity.this); myText.setTextSize(17); return myText; } }); // set the animation type of textSwitcher progDescription.setInAnimation(in); progDescription.setOutAnimation(out); title.setText(getResources().getString(R.string.first_welcome)); summary.setText(getResources().getString(R.string.first_info)); progressBar.setProgress(100); CookieSyncManager.createInstance(this); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); mWebView = (WebView) findViewById(R.id.loginWebView); try { mWebView.getSettings().setJavaScriptEnabled(true); } catch (Exception e) { } mWebView.getSettings().setAppCacheEnabled(false); mWebView.getSettings().setSavePassword(false); mWebView.getSettings().setSaveFormData(false); mWebView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView webView, String url) { Log.v("talon_login", "url: " + url); if (url != null && url.startsWith("oauth:///talonforandroid")) { handleTwitterCallback(url); } else if (url.equals("https://twitter.com/")) { webView.loadUrl(requestUrl); } else { webView.loadUrl(url); } return true; } }); noThanks.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new FollowMe().execute(); btnLoginTwitter.setText(getResources().getString(R.string.back_to_timeline)); noThanks.setVisibility(View.GONE); summary.setText(getResources().getString(R.string.third_info)); } }); btnLoginTwitter.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // Call login_activity twitter function if (btnLoginTwitter.getText().toString() .contains(getResources().getString(R.string.login_to_twitter))) { if (Utils.hasInternetConnection(context)) { btnLoginTwitter.setEnabled(false); new AlertDialog.Builder(context) .setMessage("Twitter may display that Talon cannot authenticate any more users. " + "\n\n" + "If so, and you have logged into Talon in the past, simply hit the 'Sign In' button in the top right and it will allow you to log in as normal. " + "\n\n" + "If you have never logged into Talon, then you will have to wait to login. Twitter seems to allow more users access every few hours.") .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).setNegativeButton("More Info", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse( "https://plus.google.com/117432358268488452276/posts/KG4AcH3YA2U"))); } }).show(); new RetreiveFeedTask().execute(); } else { Toast.makeText(context, getResources().getString(R.string.no_network) + "!", Toast.LENGTH_SHORT).show(); } } else if (btnLoginTwitter.getText().toString() .contains(getResources().getString(R.string.initial_sync))) { new getTimeLine().execute(); } else if (btnLoginTwitter.getText().toString() .contains(getResources().getString(R.string.no_thanks))) { btnLoginTwitter.setText(getResources().getString(R.string.back_to_timeline)); noThanks.setVisibility(View.GONE); summary.setText(getResources().getString(R.string.third_info)); } else { if (settings.timelineRefresh != 0) { // user only wants manual AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); long now = new Date().getTime(); long alarm = now + settings.timelineRefresh; PendingIntent pendingIntent = PendingIntent.getService(context, HomeFragment.HOME_REFRESH_ID, new Intent(context, TimelineRefreshService.class), 0); am.setRepeating(AlarmManager.RTC_WAKEUP, alarm, settings.timelineRefresh, pendingIntent); now = new Date().getTime(); alarm = now + settings.mentionsRefresh; PendingIntent pendingIntent2 = PendingIntent.getService(context, MentionsFragment.MENTIONS_REFRESH_ID, new Intent(context, MentionsRefreshService.class), 0); am.setRepeating(AlarmManager.RTC_WAKEUP, alarm, settings.mentionsRefresh, pendingIntent2); alarm = now + settings.dmRefresh; PendingIntent pendingIntent3 = PendingIntent.getService(context, DMFragment.DM_REFRESH_ID, new Intent(context, DirectMessageRefreshService.class), 0); am.setRepeating(AlarmManager.RTC_WAKEUP, alarm, settings.dmRefresh, pendingIntent3); } // set up the autotrim AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); long now = new Date().getTime(); long alarm = now + AlarmManager.INTERVAL_DAY; Log.v("alarm_date", "auto trim " + new Date(alarm).toString()); PendingIntent pendingIntent = PendingIntent.getService(context, 161, new Intent(context, TrimDataService.class), 0); am.set(AlarmManager.RTC_WAKEUP, alarm, pendingIntent); finish(); Intent timeline = new Intent(context, MainActivity.class); timeline.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); timeline.putExtra("tutorial", true); sharedPrefs.edit().putBoolean("should_refresh", false).commit(); sharedPrefs.edit().putBoolean("refresh_me", true).commit(); sharedPrefs.edit().putBoolean("refresh_me_mentions", true).commit(); sharedPrefs.edit().putBoolean("refresh_me_dm", true).commit(); sharedPrefs.edit().putBoolean("need_new_dm", false).commit(); sharedPrefs.edit().putBoolean("need_clean_databases_version_1_3_0", false).commit(); sharedPrefs.edit().putBoolean("setup_v_two", true).commit(); sharedPrefs.edit().putBoolean("version_2_2_7_1", false).commit(); AppSettings.invalidate(); startActivity(timeline); } } }); }
From source file:com.klinker.android.twitter.ui.setup.LoginActivity.java
License:Apache License
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); context = this; settings = AppSettings.getInstance(context); //context.sendBroadcast(new Intent("com.klinker.android.twitter.STOP_PUSH")); Utils.setUpTheme(context, settings); setContentView(R.layout.login_activity); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(settings.TWITTER_CONSUMER_KEY); builder.setOAuthConsumerSecret(settings.TWITTER_CONSUMER_SECRET); Configuration configuration = builder.build(); TwitterFactory factory = new TwitterFactory(configuration); twitter = factory.getInstance();/* w w w .j av a2s. c o m*/ btnLoginTwitter = (Button) findViewById(R.id.btnLoginTwitter); noThanks = (Button) findViewById(R.id.dont_follow); title = (TextSwitcher) findViewById(R.id.welcome); summary = (TextSwitcher) findViewById(R.id.info); progDescription = (TextSwitcher) findViewById(R.id.progress_desc); progressBar = (ProgressBar) findViewById(R.id.progress_bar); main = (LinearLayout) findViewById(R.id.mainLayout); Animation in = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left); Animation out = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right); title.setFactory(new ViewSwitcher.ViewFactory() { public View makeView() { TextView myText = new TextView(LoginActivity.this); myText.setTextSize(30); return myText; } }); // set the animation type of textSwitcher title.setInAnimation(in); title.setOutAnimation(out); summary.setFactory(new ViewSwitcher.ViewFactory() { public View makeView() { TextView myText = new TextView(LoginActivity.this); myText.setTextSize(17); return myText; } }); // set the animation type of textSwitcher summary.setInAnimation(in); summary.setOutAnimation(out); progDescription.setFactory(new ViewSwitcher.ViewFactory() { public View makeView() { TextView myText = new TextView(LoginActivity.this); myText.setTextSize(17); return myText; } }); // set the animation type of textSwitcher progDescription.setInAnimation(in); progDescription.setOutAnimation(out); title.setText(getResources().getString(R.string.first_welcome)); summary.setText(getResources().getString(R.string.first_info)); progressBar.setProgress(100); CookieSyncManager.createInstance(this); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); mWebView = (WebView) findViewById(R.id.loginWebView); try { mWebView.getSettings().setJavaScriptEnabled(true); } catch (Exception e) { } mWebView.getSettings().setAppCacheEnabled(false); mWebView.getSettings().setSavePassword(false); mWebView.getSettings().setSaveFormData(false); mWebView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView webView, String url) { if (url != null && url.startsWith("oauth:///talonforandroid")) { handleTwitterCallback(url); } else { webView.loadUrl(url); } return true; } }); noThanks.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new FollowMe().execute(); btnLoginTwitter.setText(getResources().getString(R.string.back_to_timeline)); noThanks.setVisibility(View.GONE); summary.setText(getResources().getString(R.string.third_info)); } }); btnLoginTwitter.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // Call login_activity twitter function if (btnLoginTwitter.getText().toString() .contains(getResources().getString(R.string.login_to_twitter))) { if (Utils.hasInternetConnection(context)) { btnLoginTwitter.setEnabled(false); new RetreiveFeedTask().execute(); } else { Toast.makeText(context, getResources().getString(R.string.no_network) + "!", Toast.LENGTH_SHORT).show(); } } else if (btnLoginTwitter.getText().toString() .contains(getResources().getString(R.string.initial_sync))) { new getTimeLine().execute(); } else if (btnLoginTwitter.getText().toString() .contains(getResources().getString(R.string.no_thanks))) { btnLoginTwitter.setText(getResources().getString(R.string.back_to_timeline)); noThanks.setVisibility(View.GONE); summary.setText(getResources().getString(R.string.third_info)); } else { if (settings.timelineRefresh != 0) { // user only wants manual AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); long now = new Date().getTime(); long alarm = now + settings.timelineRefresh; PendingIntent pendingIntent = PendingIntent.getService(context, HomeFragment.HOME_REFRESH_ID, new Intent(context, TimelineRefreshService.class), 0); am.setRepeating(AlarmManager.RTC_WAKEUP, alarm, settings.timelineRefresh, pendingIntent); now = new Date().getTime(); alarm = now + settings.mentionsRefresh; PendingIntent pendingIntent2 = PendingIntent.getService(context, MentionsFragment.MENTIONS_REFRESH_ID, new Intent(context, MentionsRefreshService.class), 0); am.setRepeating(AlarmManager.RTC_WAKEUP, alarm, settings.mentionsRefresh, pendingIntent2); alarm = now + settings.dmRefresh; PendingIntent pendingIntent3 = PendingIntent.getService(context, DMFragment.DM_REFRESH_ID, new Intent(context, DirectMessageRefreshService.class), 0); am.setRepeating(AlarmManager.RTC_WAKEUP, alarm, settings.dmRefresh, pendingIntent3); } // set up the autotrim AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); long now = new Date().getTime(); long alarm = now + AlarmManager.INTERVAL_DAY; Log.v("alarm_date", "auto trim " + new Date(alarm).toString()); PendingIntent pendingIntent = PendingIntent.getService(context, 161, new Intent(context, TrimDataService.class), 0); am.set(AlarmManager.RTC_WAKEUP, alarm, pendingIntent); finish(); Intent timeline = new Intent(context, MainActivity.class); timeline.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); timeline.putExtra("tutorial", true); sharedPrefs.edit().putBoolean("should_refresh", false).commit(); sharedPrefs.edit().putBoolean("refresh_me", true).commit(); sharedPrefs.edit().putBoolean("refresh_me_mentions", true).commit(); sharedPrefs.edit().putBoolean("refresh_me_dm", true).commit(); sharedPrefs.edit().putBoolean("need_new_dm", false).commit(); sharedPrefs.edit().putBoolean("need_clean_databases_version_1_3_0", false).commit(); sharedPrefs.edit().putBoolean("setup_v_two", true).commit(); sharedPrefs.edit().putBoolean("version_2_2_7_1", false).commit(); AppSettings.invalidate(); startActivity(timeline); } } }); }
From source file:com.lbarriosh.sentimentanalyzer.downloads.TweetsDownloader.java
License:Open Source License
public TweetsDownloader(String api_key, String api_secret, String access_token, String access_token_secret) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey(api_key);/*from w w w. j a v a2 s. co m*/ cb.setOAuthConsumerSecret(api_secret); cb.setOAuthAccessToken(access_token); cb.setOAuthAccessTokenSecret(access_token_secret); this.tf = new TwitterFactory(cb.build()); }
From source file:com.learnncode.demotwitterimagepost.HelperMethods.java
License:Apache License
public static void postToTwitter(Context context, final Activity callingActivity, final String message, final TwitterCallback postResponse) { if (!LoginActivity.isActive(context)) { postResponse.onFinsihed(false);/*from ww w . j a v a 2 s . c o m*/ return; } final ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setOAuthConsumerKey(context.getResources().getString(R.string.twitter_consumer_key)); configurationBuilder .setOAuthConsumerSecret(context.getResources().getString(R.string.twitter_consumer_secret)); configurationBuilder.setOAuthAccessToken(LoginActivity.getAccessToken(context)); configurationBuilder.setOAuthAccessTokenSecret(LoginActivity.getAccessTokenSecret(context)); final Configuration configuration = configurationBuilder.build(); final Twitter twitter = new TwitterFactory(configuration).getInstance(); new Thread(new Runnable() { private double x; @Override public void run() { boolean success = true; try { x = Math.random(); twitter.updateStatus(message + " " + x); } catch (final TwitterException e) { e.printStackTrace(); success = false; } final boolean finalSuccess = success; callingActivity.runOnUiThread(new Runnable() { @Override public void run() { postResponse.onFinsihed(finalSuccess); } }); } }).start(); }
From source file:com.learnncode.demotwitterimagepost.HelperMethods.java
License:Apache License
public static void postToTwitterWithImage(Context context, final Activity callingActivity, final String imageUrl, final String message, final TwitterCallback postResponse) { if (!LoginActivity.isActive(context)) { postResponse.onFinsihed(false);// www . j a v a 2 s .com return; } final ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setOAuthConsumerKey(context.getResources().getString(R.string.twitter_consumer_key)); configurationBuilder .setOAuthConsumerSecret(context.getResources().getString(R.string.twitter_consumer_secret)); configurationBuilder.setOAuthAccessToken(LoginActivity.getAccessToken(context)); configurationBuilder.setOAuthAccessTokenSecret(LoginActivity.getAccessTokenSecret(context)); final Configuration configuration = configurationBuilder.build(); final Twitter twitter = new TwitterFactory(configuration).getInstance(); final File file = new File(imageUrl); new Thread(new Runnable() { private double x; @Override public void run() { boolean success = true; try { x = Math.random(); if (file.exists()) { final StatusUpdate status = new StatusUpdate(message); status.setMedia(file); twitter.updateStatus(status); } else { Log.d(TAG, "----- Invalid File ----------"); success = false; } } catch (final Exception e) { e.printStackTrace(); success = false; } final boolean finalSuccess = success; callingActivity.runOnUiThread(new Runnable() { @Override public void run() { postResponse.onFinsihed(finalSuccess); } }); } }).start(); }
From source file:com.learnncode.demotwitterimagepost.HelperMethods.java
License:Apache License
public static void postToTwitterWithInputStream(Context context, final Activity callingActivity, final InputStream inputStream, final String message, final TwitterCallback postResponse) { if (!LoginActivity.isActive(context)) { postResponse.onFinsihed(false);/*from ww w. j a v a 2s. c om*/ return; } final ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setOAuthConsumerKey(context.getResources().getString(R.string.twitter_consumer_key)); configurationBuilder .setOAuthConsumerSecret(context.getResources().getString(R.string.twitter_consumer_secret)); configurationBuilder.setOAuthAccessToken(LoginActivity.getAccessToken(context)); configurationBuilder.setOAuthAccessTokenSecret(LoginActivity.getAccessTokenSecret(context)); final Configuration configuration = configurationBuilder.build(); final Twitter twitter = new TwitterFactory(configuration).getInstance(); new Thread(new Runnable() { private double x; @Override public void run() { boolean success = true; try { x = Math.random(); if (inputStream != null) { final StatusUpdate status = new StatusUpdate(message); status.setMedia("GIF image", inputStream); twitter.updateStatus(status); } else { Log.d(TAG, "----- Invalid File ----------"); success = false; } } catch (final Exception e) { e.printStackTrace(); success = false; } final boolean finalSuccess = success; callingActivity.runOnUiThread(new Runnable() { @Override public void run() { postResponse.onFinsihed(finalSuccess); } }); } }).start(); }