I have to add an option to my game for posting highscores to twitter. The idea is that the app has it's own twitter account and the user can upload the score to this specific account with a click on a button or a menu item (haven't decided how the UI looks like yet).
I have found many tutorials like this:
http://blog.doityourselfandroid.com/2011/02/13/guide-to-integrating-twitter-android-application/
,which show how to post to twitter from apps but in all of these solutions the user needs to login with his/her own account.
Any suggestions are welcome. Thank you.
I have found a solution for this problem. Thought I share it here in case anyone has the same problem.
- First you need to create the account for your app on twitter
- Go to this page and log in with the created account
- Move your mouse over your account name in the upper right corner and
click "My applications"
- Click on "Create a new application" on the right
- Fill in the form and create the application
- Go to Settings and under Application type set the Access type to
"Read and Write" and save the settings
- Return to the "Details" page and scroll down to the bottom and click
the "Create access token" button
- Use these generated tokens and the other ones ("Consumer key" and
"Consumer secret") which are shown above these previously generated
tokens on the same page to post tweets from your app
Here's the code I used in my app:
You need to include the twitter4j-core-android-2.2.5.jar package for this. You can download it from here: http://twitter4j.org/archive/twitter4j-android-2.2.5.zip
tweet=(Button)findViewById(R.id.tweetbtn);
message=(EditText)findViewById(R.id.messagetxt);
tweet.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
String token ="<Your access token>";
String secret = "<Your access token secret>";
AccessToken a = new AccessToken(token,secret);
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer("<Your consumer key>", "<Your consumer secret>");
twitter.setOAuthAccessToken(a);
try {
twitter.updateStatus(message.getText().toString());
} catch (TwitterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
the new link for download
http://twitter4j.org/archive/twitter4j-android-2.2.5.zip
old link does not work