When i used StatusesService's method "update" to tweet,there is exception here that i don't konw

android

#1

hi ,
there is a exception ,please help me.
here is my code: in my vode

session!=null,   mediaIdString!=null;

 TwitterApiClient apiClient = TwitterCore.getInstance().getApiClient(session);
 final com.twitter.sdk.android.core.services.StatusesService service = apiClient.getStatusesService();
Call<Tweet> update = service.update("test", null, null, null, null, null, null, null, mediaIdString);
                update.enqueue(new Callback<Tweet>() {
                    @Override
                    public void success(Result<Tweet> result) {
                        Log.e(TAG, "Result<Tweet> result" + result.data.toString());

                    }

                    @Override
                    public void failure(TwitterException exception) {
                        Log.e(TAG, "Result<Tweet> result" + exception.getMessage());
                    }
                });

but the log is :

E/Twitter:
 Unexpected response
java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.isEmpty()' on a null object reference
  at com.twitter.sdk.android.core.Callback.onResponse(Callback.java:42)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
                                                                      at android.os.Handler.handleCallback(Handler.java:739)
                                                                      at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                      at android.os.Looper.loop(Looper.java:135)
                                                                      at android.app.ActivityThread.main(ActivityThread.java:5400)
                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                      at java.lang.reflect.Method.invoke(Method.java:372)
                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1037)
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
E/silentshare------------: Result<Tweet> resultHTTP request failed, Status: 401

#4

Hey @aheidou,

I’m replying here instead of your email into our support team. It sounds like you’re trying to update data but haven’t gotten the data yet to update. Can you confirm that you’ve got the data in the service that you want?


#6

@bonnell thank you ,what i want to do is share in the background with image and text when i have signed in twitter ,maybe you have another way to complete this function? in my mind, i find interface StatusesService ,first i upload one image ,after i get midiaIdString,execute the method above ,here my code:

TwitterApiClient apiClient = TwitterCore.getInstance().getApiClient(session);
MediaService mediaService = apiClient.getMediaService();
final com.twitter.sdk.android.core.services.StatusesService service = apiClient.getStatusesService();
Log.e(TAG, “service” + service);

//上传图片
byte[] byte_content = mByteContent;
byte[] byte_content_base64 = mByte64Content;

RequestBody media = RequestBody.create(null, byte_content);
RequestBody mediaData = RequestBody.create(null, byte_content_base64);

Call<Media> upload = mediaService.upload(media, mediaData, null);
upload.enqueue(new Callback<Media>() {
    @Override
    public void success(Result<Media> result) {
        mediaIdString = result.data.mediaIdString;
        Call<Tweet> update = service.update("test", null, null, null, null, null, null, null, mediaIdString);
        update.enqueue(new Callback<Tweet>() {
            @Override
            public void success(Result<Tweet> result) {
                Log.e(TAG, "Result<Tweet> result" + result.data.toString());

            }

            @Override
            public void failure(TwitterException exception) {
                Log.e(TAG, "Result<Tweet> result" + exception.getMessage());
            }
        });
    }

    @Override
    public void failure(TwitterException exception) {
        Log.e(TAG, "Result<Media> result" + exception.getMessage());
    }
});

#7

Hey @aheidou,

We don’t have a way through Twitter Kit to share or compose a tweet from the background, users need to agree to the tweet by having the text display before they tweet. You can see our guidelines for composing tweets here: https://docs.fabric.io/android/twitter/compose-tweets.html

-Mike


#8

ok,thank you


#9

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.