Reputation: 678
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.
Upvotes: 0
Views: 38
Reputation: 27221
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();
Upvotes: 0
Reputation: 892
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!");
Upvotes: 1