我想在My Application中实现Twitter。 有了它,我想上传照片。 我还想使用Twitter的默认Auth然后哪一个是在一键点击上发布照片的最佳方式,并获得照片在Twitter上发布的消息。
我想要任何帮助我申请的简单演示。
感谢。
答案 0 :(得分:3)
您可以使用以下链接
请在下面的方法中
public String postPicture(String fileName) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
String provider = preferences.getString("pictureService","yfrog");
try {
File file = new File(fileName);
MediaProvider mProvider ;
if (provider.equals("yfrog"))
mProvider = MediaProvider.YFROG;
else if (provider.equals("twitpic"))
mProvider = MediaProvider.TWITPIC;
else
throw new IllegalArgumentException("Picture provider " + provider + " unknown");
String accessTokenToken = account.getAccessTokenKey();
String accessTokenSecret = account.getAccessTokenSecret();
Properties props = new Properties();
props.put(PropertyConfiguration.MEDIA_PROVIDER,mProvider);
props.put(PropertyConfiguration.OAUTH_ACCESS_TOKEN,accessTokenToken);
props.put(PropertyConfiguration.OAUTH_ACCESS_TOKEN_SECRET,accessTokenSecret);
props.put(PropertyConfiguration.OAUTH_CONSUMER_KEY,TwitterConsumerToken.consumerKey);
props.put(PropertyConfiguration.OAUTH_CONSUMER_SECRET,TwitterConsumerToken.consumerSecret);
Configuration conf = new PropertyConfiguration(props);
ImageUploaderFactory factory = new ImageUploaderFactory(conf);
ImageUpload upload = factory.getInstance(mProvider);
String url = upload.upload(file);
return url;
} catch (Exception e) {
e.printStackTrace(); // TODO: Customise this generated block
}
return null;
}