I have tried upload a photo in twitter but the status is send not photo. Can anyone suggest some help?
Asked
Active
Viewed 5,979 times
2
-
2Welcome to SO. What have you tries this far? Are you using an API? – vbence Apr 28 '11 at 08:56
-
see here: http://stackoverflow.com/questions/8381671/is-there-any-twitter-demo-exmaple-to-post-photo-on-twitter-with-using-oauth-in-t – Shreyash Mahajan Nov 06 '12 at 09:34
4 Answers
2
Try this code..
final SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(this);
String token = prefs.getString(OAuth.OAUTH_TOKEN, "") != null ? prefs
.getString(OAuth.OAUTH_TOKEN, "") : "";
String secret = prefs.getString(OAuth.OAUTH_TOKEN_SECRET, "") != null ? prefs
.getString(OAuth.OAUTH_TOKEN_SECRET, "") : "";
if (token != null && !token.trim().equals("") && secret != null
&& !secret.trim().equals("")) {
AccessToken a = new AccessToken(token, secret);
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(Constants.CONSUMER_KEY,
Constants.CONSUMER_SECRET);
twitter.setOAuthAccessToken(a);
Configuration conf = new ConfigurationBuilder()
.setOAuthConsumerKey(Constants.CONSUMER_KEY)
.setOAuthConsumerSecret(Constants.CONSUMER_SECRET)
.setOAuthAccessToken(a.getToken())
.setOAuthAccessTokenSecret(a.getTokenSecret())
.build();
OAuthAuthorization auth = new OAuthAuthorization (conf, conf.getOAuthConsumerKey (), conf.getOAuthConsumerSecret (), new AccessToken (conf.getOAuthAccessToken (), AuthAccessTokenSecret ()));
ImageUpload upload = ImageUpload.getTwitpicUploader ("fa6707f43c41faab003dc134348acabd",auth);
url = upload.upload(new File(path));
twitter.updateStatus(url);
///Add twitter4j-core-2.1.11jar to libs

user1640247
- 70
- 2
- 6
2
You need to upload the picture to a picture service like twitpic, which will return an URL, that you then put into your status update.
There are libraries like Twitter4J out there, that can help you with this task.
Have a look at Zwitscher on how to use it: code to upload

Heiko Rupp
- 30,426
- 13
- 82
- 119
1
Twitter4j 3.0.3 has updated its ImageUpload
class. ImageUpload.getTwitpicUploader
method is now deprecated; it has only ImageUpload.upload
method. Also, you have to add these two .jar on your projects build path:
- twitter4j-core-3.0.3.jar
- twitter4j-media-support-3.0.3.jar
You can get more info at: http://twitter4j.org/oldjavadocs/3.0.3/index.html

orique
- 1,295
- 1
- 27
- 36

sojitra.sagar
- 11
- 1
1
First you need to create an app on twitter
here is code to post message on twitter
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
configurationBuilder.setOAuthConsumerKey(context.getResources().getString(R.string.twitter_consumer_key));
configurationBuilder.setOAuthConsumerSecret(context.getResources().getString(R.string.twitter_consumer_secret));
configurationBuilder.setOAuthAccessToken(LoginActivity.getAccessToken((context)));
configurationBuilder.setOAuthAccessTokenSecret(LoginActivity.getAccessTokenSecret(context));
Configuration configuration = configurationBuilder.build();
final Twitter twitter = new TwitterFactory(configuration).getInstance();
new Thread(new Runnable() {
private double x;
@Override
public void run() {
boolean success = true;
try {
x = Math.random();
twitter.updateStatus(message +" "+x);
} catch (TwitterException e) {
e.printStackTrace();
success = false;
}
final boolean finalSuccess = success;
callingActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
postResponse.onFinsihed(finalSuccess);
}
});
}
}).start();
check this tutorial for more details.

Prachi
- 2,559
- 4
- 25
- 37