How to add image with tweet

android
fabric
image

#1

I have done this. But after calling call.enqueue, neither success or failure is called. Please tell me what I have been doing wrong?

        File file = new File(filePath);
      
        TwitterSession session = TwitterCore.getInstance()
                .getSessionManager().getActiveSession();

        TwitterApiClient twitterApiClient = TwitterCore.getInstance().getApiClient(session);
        MediaService ms = twitterApiClient.getMediaService();

        MediaType type = MediaType.parse("image/*");

        RequestBody body = RequestBody.create(type, file);

        Call<Media> mediaCall= ms.upload(body, null, null);

        mediaCall.enqueue(new Callback<Media>() {
            @Override
            public void failure(TwitterException exception)
            {
                Log.d("failure", "mediaUpload");
                dialog.dismiss();
            }

            @Override
            public void success(Result<Media> result)
            {
                // getting tweet in string
                String tweetStr = edit_tweet.getText().toString();

                // post tweet only if it is not empty
                if (!TextUtils.isEmpty(tweetStr)) {
                    // EditText is not empty
                    // Check if char count is exceeding 140 limit
                    if (tweetStr.length() > 140) {
                        Toast.makeText(PostTweetActivity.this,
                                "You have exceeded the 140 character limit",
                                Toast.LENGTH_SHORT).show();
                        return;
                    }
                    // getting twitter api client and session
                    StatusesService statusesService =
                            TwitterCore.getInstance().getApiClient().getStatusesService();


                    Call<Tweet> tweetCall= statusesService.update
                            (       tweetStr,
                                    null, false,
                                    null, null, null,
                                    true, false,
                                    result.data.mediaIdString
                            );

                    tweetCall.enqueue(new Callback<Tweet>()
                    {
                        @Override
                        public void success(Result<Tweet> result) {
                            //dismiss the progress dialog
                            dialog.dismiss();
                            //close the activity
                            finish();
                        }

                        public void failure(TwitterException exception)
                        {
                            //dismiss the progress dialog
                            dialog.dismiss();
                            // showing error to user
                            Toast.makeText(PostTweetActivity.this,
                                    R.string.error_msg_post_tweet, Toast.LENGTH_SHORT)
                                    .show();
                        }
                    });
                }

        });

#2

He6y @ashish_sarin,

Can you please enable debug mode and share the Logcat output?

Thanks,
Mike


#3

I don’t know how to enable debug mode. This is what I am doing in my MainActivity’s onCreate method.

    // setting up the twitter kit
    TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
    Fabric.with(this, new Twitter(authConfig));

Sorry, I am new to android. Can you help me with this?


#4

You’d want to use the following code:

final Fabric fabric = new Fabric.Builder(this).kits(new TwitterCore(authConfig), new Digits()).debuggable(true).build();
Fabric.with(fabric);

#5

Here are the logs:

09-19 21:20:44.982: I/art(13242): Late-enabling -Xcheck:jni
09-19 21:20:45.025: W/System(13242): ClassLoader referenced unknown path: /data/app/com.sareen.squarelabs.humblebrag-1/lib/arm
09-19 21:20:45.052: I/art(13242): Ignoring second debugger – accepting and dropping
09-19 21:20:45.445: W/System(13242): ClassLoader referenced unknown path: /data/app/com.sareen.squarelabs.humblebrag-1/lib/arm
09-19 21:20:45.646: W/art(13242): Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
09-19 21:20:46.008: D/Twitter(13242): Custom SSL pinning enabled
09-19 21:20:46.067: D/Fabric(13242): Initializing io.fabric.sdk.android:fabric [Version: 1.3.13.142], with the following kits:
09-19 21:20:46.067: D/Fabric(13242): com.twitter.sdk.android:twitter-core [Version: 2.0.0.142]
09-19 21:20:46.067: D/Fabric(13242): com.twitter.sdk.android:twitter [Version: 2.0.0.142]
09-19 21:20:46.067: D/Fabric(13242): com.twitter.sdk.android:tweet-composer [Version: 2.0.0.142]
09-19 21:20:46.067: D/Fabric(13242): com.twitter.sdk.android:tweet-ui [Version: 2.0.0.142]
09-19 21:20:46.103: D/Fabric(13242): Could not get parcel from Google Play Service to capture AdvertisingId
09-19 21:20:46.103: D/Fabric(13242): Could not get parcel from Google Play Service to capture Advertising limitAdTracking
09-19 21:20:46.106: D/Fabric(13242): AdvertisingInfo not present
09-19 21:20:46.115: D/Fabric(13242): Build ID is: 85ec8f8e-072b-4277-91a1-7581e8014847
09-19 21:20:46.134: D/Fabric(13242): Requesting settings from https://settings.crashlytics.com/spi/v2/platforms/android/apps/com.sareen.squarelabs.humblebrag/settings
09-19 21:20:46.134: D/Fabric(13242): Settings query params were: {icon_hash=4ed054f1deb7f88fa548b8fe4e6e4366f6798b67, display_version=1.3.2, source=1, instance=a56b0fde3dcd1a1a21c6b8b854ea677fbd48c5ec, build_version=6}
09-19 21:20:46.493: D/OpenGLRenderer(13242): Use EGL_SWAP_BEHAVIOR_PRESERVED: true
09-19 21:20:46.561: I/Adreno(13242): QUALCOMM build : 3d89180, I1b38baa288
09-19 21:20:46.561: I/Adreno(13242): Build Date : 03/30/16
09-19 21:20:46.561: I/Adreno(13242): OpenGL ES Shader Compiler Version: XE031.06.00.02
09-19 21:20:46.561: I/Adreno(13242): Local Branch : master_AU27
09-19 21:20:46.561: I/Adreno(13242): Remote Branch :
09-19 21:20:46.561: I/Adreno(13242): Remote Branch :
09-19 21:20:46.561: I/Adreno(13242): Reconstruct Branch :
09-19 21:20:46.572: I/OpenGLRenderer(13242): Initialized EGL, version 1.4
09-19 21:20:55.570: D/Fabric(13242): Settings result was: 200
09-19 21:20:55.575: D/Fabric(13242): Settings request ID: 01b5c87a4e0dde7746cddabd8dcee0f9
09-19 21:20:55.583: D/Fabric(13242): Writing settings to cache file…
09-19 21:20:55.587: D/Fabric(13242): Loaded settings: {“settings_version”:2,“cache_duration”:60,“features”:{“collect_logged_exceptions”:true,“collect_reports”:true,“collect_analytics”:false,“prompt_enabled”:false,“push_enabled”:true},“analytics”:{“url”:“https://e.crashlytics.com/spi/v2/events",“flush_interval_secs”:600,“max_file_count_per_send”:1,“track_custom_events”:true,“track_predefined_events”:true,“track_view_controllers”:false,“flush_on_background”:true,“max_byte_size_per_file”:8000,“max_pending_send_file_count”:100,“sampling_rate”:1},“beta”:{“update_suspend_duration”:1800,“update_endpoint”:“https://api.crashlytics.com/spi/v2/platforms/android/apps/com.sareen.squarelabs.humblebrag/beta_update_check”},“app”:{“identifier”:“com.sareen.squarelabs.humblebrag”,“status”:“activated”,“url”:“https://api.crashlytics.com/spi/v1/platforms/android/apps/com.sareen.squarelabs.humblebrag”,“reports_url”:“https://reports.crashlytics.com/spi/v1/platforms/android/apps/com.sareen.squarelabs.humblebrag/reports”,“update_required”:false},“session”:{“log_buffer_size”:64000,“max_chained_exception_depth”:16,“max_custom_exception_events”:8,“max_custom_key_value_pairs”:64,“identifier_mask”:255},“prompt”:{“title”:"Send Crash Report?”,“message”:“Looks like we crashed! Please help us fix the problem by sending a crash report.”,“send_button_title”:“Send”,“show_cancel_button”:true,“cancel_button_title”:“Don’t Send”,“show_always_send_button”:true,“always_send_button_title”:“Always Send”},“expires_at”:1474300315583}
09-19 21:20:55.588: D/Fabric(13242): Build ID is: 85ec8f8e-072b-4277-91a1-7581e8014847
09-19 21:20:55.624: W/Settings(13242): Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
09-19 21:21:14.982: I/art(13242): Debugger is no longer active
09-19 21:21:46.358: D/PostTweetActivity(13242): onCreate
09-19 21:21:46.510: D/OpenGLRenderer(13242): endAllActiveAnimators on 0xb795da60 (RippleDrawable) with handle 0xb7b524e8
09-19 21:21:52.042: D/OpenGLRenderer(13242): endAllActiveAnimators on 0xb7a8b158 (RippleDrawable) with handle 0xb7b3e8d0
09-19 21:21:59.871: D/PostTweetActivity(13242): onClickTweet