4

After fabric removal , now Twitter kit 3 is used in the android

Case :

  • I need share the text , image and video without opening the Twitter Composer

  • I am sharing the text , image and the video using twitter kit 3 by using the method StatusesService

  • So i can share the text by using below code :

    final TwitterSession session = TwitterCore.getInstance().getSessionManager().getActiveSession();
    StatusesService statusesService = TwitterCore.getInstance().getApiClient(session).getStatusesService();
    statusesService.update("Click this link "+getShareLink(),null,null,null,null,null,null,null,null).enqueue(new Callback<Tweet>() {
        @Override
        public void success(Result<Tweet> result) {
            Toast.makeText(context,"Tweet success ",Toast.LENGTH_SHORT).show();
            Log.e(TAG,"Twitter "+ result.data.toString());
        }
    
        @Override
        public void failure(TwitterException exception) {
            Toast.makeText(context,"Tweet failure ",Toast.LENGTH_SHORT).show();
            Log.e(TAG,"Twitter "+ exception.getMessage());
        }
    });
    
  • For image upload we can use MediaService and for uploading it we can use MediaService.upload() method , but in the MediaServicethey are only prompt the images to upload and i also checked their docs .

  • And now How to share Video in the Twitter kit 3 using StatuesServices or any other method ?

prasanthMurugan
  • 597
  • 6
  • 21
Ko Vartthan
  • 434
  • 1
  • 4
  • 22

2 Answers2

3

1) The native video upload support is only available with iOS (See attachment section)

2) Quick Bad workaround You can convert video to gif and upload it.

3) Proper solution:

You can extend the kit, and use the media/uploads endpoint.

See this to make a post request.

Optional
  • 4,387
  • 4
  • 27
  • 45
0

It's working on tweet-composer:3.3.0.

I simply added the video Uri to the place where we normally add the image Uri. It worked unexpectedly.

private void shareVideoViaTwitter(File file) {
    try {
        Uri uri = FileProvider.getUriForFile(context, "com.civ.petcam.fileprovider", file);

        context.startActivity(new TweetComposer.Builder(context)
                .text("This video is made with PetCamera")
                .url(new URL("https://play.google.com/store/apps/details?id=com.civ.petcam"))
                .image(uri).createIntent().setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));

        onVideoShareCompleteListener.onVideoShareComplete("twitter");
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}