Skip to content

Instantly share code, notes, and snippets.

@nimran
Created December 5, 2016 17:00
Show Gist options
  • Save nimran/933189b1e8186f9df4c6d6581d012d68 to your computer and use it in GitHub Desktop.
Save nimran/933189b1e8186f9df4c6d6581d012d68 to your computer and use it in GitHub Desktop.
public void shareImageToTwitter() {
TwitterApiClient twitterApiClient = TwitterCore.getInstance().getApiClient();
File photo = new File(localImagePath);
TypedFile typedFile = new TypedFile("application/octet-stream", photo);
MediaService ms = twitterApiClient.getMediaService();
ms.upload(typedFile, null, null, new Callback<Media>() {
@Override
public void success(Result<Media> mediaResult) {
long id = mediaResult.data.mediaId;
Log.e("Twi Share Successfull", String.valueOf(id));
StatusesService statusesService = TwitterCore.getInstance().getApiClient().getStatusesService();
//
statusesService.update(description, null, false, null, null, null, true, false, mediaResult.data.mediaIdString, new Callback<Tweet>() {
@Override
public void success(Result<Tweet> tweetResult) {
Log.e("Twit Share Successfull", tweetResult.toString());
Toast.makeText(theActivity, "Twitter Post Successfull", Toast.LENGTH_LONG).show();
// dbAdapter.savePost(localPostId, "twitter_id", String.valueOf(tweetResult.data.getId()));
}
@Override
public void failure(TwitterException e) {
Log.e("TwitterException", e.toString());
Toast.makeText(theActivity, "Twitter Post Error", Toast.LENGTH_LONG).show();
}
});
}
@Override
public void failure(TwitterException e) {
Log.e("TwitterException", e.toString());
Toast.makeText(theActivity, "Twitter Post Error", Toast.LENGTH_LONG).show();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment