Twitter Application Setup and Updating Twitter Status (Tweeting)


#1

Hello everyone, I have been assigned the task of making it possible to update my twitter status using the OAuth tool (programming in java using the twitter4j library in Eclipse)…but I have been trying at it for the last couple of days and I have ran into a few problems so I want to make sure to establish the information needed correctly.

First: The application creation: I am new to this OAuth tool and the whole application creation using the dev.twitter.com tools. First I am confused as to what my settings should be for the application when I create it, like what my website name should be?(I just put a random website, because I don’t actually have the application on the web I am just running the code) and what should the CallbackURL (Have no idea whether I need this or not) be? All I am trying to do is write java code using Eclipse and the twitter4j library than running it to update my twitter status something like this:

import twitter4j.Twitter;

import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.auth.OAuthAuthorization;
import twitter4j.conf.ConfigurationBuilder;

public class TwitterTest {
        private static final String ACCESS_TOKEN = "MY ACCESS_TOKEN";
        private static final String ACCESS_TOKEN_SECRET = "MY ACCESS_TOKEN_SECRET";
        private static final String CONSUMER_KEY = "MY CONSUMER_KEY";
        private static final String CONSUMER_SECRET = "MY CONSUMER_SECRET";

    public static void main(String[] args) {
        ConfigurationBuilder builder = new ConfigurationBuilder();
        builder.setOAuthAccessToken(ACCESS_TOKEN);
        builder.setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET);
        builder.setOAuthConsumerKey(CONSUMER_KEY);
        builder.setOAuthConsumerSecret(CONSUMER_SECRET);
        OAuthAuthorization auth = new OAuthAuthorization(builder.build());
        Twitter twitter = new TwitterFactory().getInstance(auth);
		try {
			twitter.updateStatus("Hello World!");
		} catch (TwitterException e) {
			System.err.println("Error occurred while updating the status!");
			return;
		}
        System.out.println("Successfully updated the status.");
    }
}

So if anyone could help me as to how to actually get it to where I can just put in my Keys/Secret Codes in the code above and then run the code and make it update my status (tweet) Hello World! on my twitter account that would be great!


#2

/* Connect to twitter and update your status and send copy to your e-mail */
package abhinav.twitter.test;

import twitter4j.DirectMessage;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.auth.OAuthAuthorization;
import twitter4j.conf.ConfigurationBuilder;

public class TwitterTest1 {

    private static final String ACCESS_TOKEN = "Your access token key";

    private static final String ACCESS_TOKEN_SECRET = "your access token secret key";

    private static final String CONSUMER_KEY = "your consumer key";

    private static final String CONSUMER_SECRET = "your consumer secret key";



public static void main(String[] args) {

    ConfigurationBuilder builder = new ConfigurationBuilder();

    builder.setOAuthAccessToken(ACCESS_TOKEN);

    builder.setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET);

    builder.setOAuthConsumerKey(CONSUMER_KEY);

    builder.setOAuthConsumerSecret(CONSUMER_SECRET);

    OAuthAuthorization auth = new OAuthAuthorization(builder.build());

    Twitter twitter =  new TwitterFactory().getInstance(auth);
    
    // The factory instance is re-useable and thread safe.
    try {
    	
        /*Twitter sender = new TwitterFactory().getInstance(auth);
        DirectMessage message = sender.sendDirectMessage(recipientId, message);
        System.out.println("Sent: " message.getText() + " to @" + message.getRecipientScreenName());*/
    
    DirectMessage message = twitter.sendDirectMessage("@Abhinavkumar_31", "Move towards heaven!!!");
    System.out.println("Sender Screen Name " +message.getSenderScreenName());
    System.out.println("Sender Id " +message.getSenderId());
    System.out.println("Recipient Screen Name @"+message.getRecipientScreenName());
    System.out.println("Rccipient Id " +message.getRecipientId());
           
  //System.out.println("Sent: " message.getText()+ " to @ "+ message.getRecipientScreenName());

   
    twitter.updateStatus("We have to move towards heaven!!!!!!!!!!!!!!");

} catch (TwitterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

    System.out.println("Successfully updated the status.");

}

}


#3

It is unwise to post your consumer key and secret here, as well as access token details. You should reset your application keys right away.


#4

Muchas gracias, tremendamente util.


#5

how to get the access_token and access_token_secret?
can anyone share some sample code to get them?


#6

can any one write java code for configure app with url…


#7

iam unable to import twitterfactory


#8

Thanks


#9

setOAuthConsumerSecret (CONSUMER_SECRET);tranngochiep007 </ code> tagek- , , , – …


#10

is possible to obtain the twitter account from the telephone and send a “Tweet” to another user?
Thanks in advance.