Created
December 5, 2016 17:00
-
-
Save nimran/933189b1e8186f9df4c6d6581d012d68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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