Posting a tweet on Twitter is different than how to get a timeline.
Given Twitter4J, the scenarios may be as follows:
This requires that you have an instance of the Twitter class that is allowed.
To complete the timeline, follow these steps:
Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(consumerKey, consumerSecret); RequestToken requestToken = twitter.getOAuthRequestToken(CALLBACKURL); ... ...
After successfully validating OAuth, you will get the oauth_verifier variable, and then create an AccessToken with the following lines:
AccessToken accessToken = twitter.getOAuthAccessToken(requestToken,oauth_verifier); String token = accessToken.getToken(), secret = accessToken.getTokenSecret();
Save the above token and secret somewhere, it will be used when creating the AccessToken later.
Now the code to update the status:
AccessToken accessToken = new AccessToken(token,secret); Twitter twitter = new TwitterFactory().getOAuthAuthorizedInstance(consumerKey,consumerSecret,accessToken); Status status = twitter.updateStatus("My First Status Update"); statusId = (int)status.getId();
This will update the My First Status Update message on your timeline and get the status ID in the statusId variable.
For a working example of using OAuth to implement twitter login and get the first tweet of your timeline, click this link to my blog post.
Iām sure that after a little modification of this and using the above code in it, you can also convert it to a tweet posting code!