0

I am developing an android app and I want to share some text content via Twitter. User will just click one button and i will push a tweet like instagram and foursquare. I have done some search but all the examples requires user to click tweet button. I want to sende automatically in the background. I know the text already, user will just click a button. Is there any example for this.

Thank you already.

starrystar
  • 668
  • 3
  • 8
  • 22
  • use this link http://stackoverflow.com/a/38967146/5305430 and instead of watsapp package name use this `com.twitter.android` – sushildlh Aug 31 '16 at 09:28

2 Answers2

1

You could maybe use Twitter4J:

Setup the authentification:

ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
  .setOAuthConsumerKey("*********************")
  .setOAuthConsumerSecret("******************************************")
  .setOAuthAccessToken("**************************************************")
  .setOAuthAccessTokenSecret("******************************************");
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();

Post a tweet:

Status status = tf.updateStatus("Hello World!");
jdstaerk
  • 882
  • 1
  • 13
  • 30
0

It is possible to use Twitter Rest API

https://docs.fabric.io/android/twitter/access-rest-api.html

E.g.,

https://docs.fabric.io/android/twitter/log-in-with-twitter.html#login-with-twitter

Sample code to retrieve token, secret:

TwitterSession session = Twitter.getSessionManager().getActiveSession();
TwitterAuthToken authToken = session.getAuthToken();
String token = authToken.token;
String secret = authToken.secret;

Sample code to send a message:

TweetComposer.Builder builder = new TweetComposer.Builder(this)
     .text("just setting up my Fabric.")
     .image(myImageUri);
builder.show();
Vyacheslav
  • 26,359
  • 19
  • 112
  • 194