简体   繁体   中英

Android Fabric Twitter error

I am integrating twitter in my application using fabric , In that i want to show users all friends/following list.

I successfully get current user name, and id but when i try to get following list it show me error Service methods cannot return void. in line ** new MyTwitterApiClient(session).getCustomService().show** my code is following.

Please any one help me to solve out that or any other method to get user following list.

my twitter button in xml file :

  <Button
            android:id="@+id/btn_twitter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/ll_mainBar"
            android:layout_gravity="center"
            android:layout_marginLeft="10dp"
            android:background="@color/color_drawer_orange"
            android:gravity="center"
            android:hint="Twiiter"
            android:padding="5dp"
            android:textColor="@color/color_white"
            android:textColorHint="@color/color_white" />

In my class file :

      btn_twitter.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            mTwitterAuthClient.authorize(SocialIntegrationFragment.this, new Callback<TwitterSession>() {
                @Override
                public void success(Result<TwitterSession> result) {
                    final TwitterSession session = Twitter.getSessionManager().getActiveSession();
                    Log.e(TAG, "UserName===================>" + session.getUserName());
                    Log.e(TAG, "UserId===================>" + session.getUserId());
                    Log.e(TAG, "ID===================>" + session.getId());
                    Log.e(TAG, "Token===================>" + session.getAuthToken());

                    // above all getting successfully

                    final String[] profile_image = {""};
                    final String[] email = {""};
                    final String[] name = new String[1];

                    // but getting error in following line : for getting following list

                    new MyTwitterApiClient(session).getCustomService().show(session.getId(), null, true, true, 100, new Callback<Followers>() {
                        @Override
                        public void success(Result<Followers> result) {
                            Log.i("Get success", "" + result.data.users.size());
                        }

                        @Override
                        public void failure(TwitterException e) {
                            Log.i("Get fail", "" + e.getMessage());
                        }
                    });

                }

                @Override
                public void failure(TwitterException exception) {

                }
            });

        }
    });

// other methods

 public class Followers {
   @SerializedName("users")
    public final List<User> users;

    public Followers(List<User> users) {
        this.users = users;
    }
}

class MyTwitterApiClient extends TwitterApiClient {
    public MyTwitterApiClient(TwitterSession session) {
        super(session);
    }

    public CustomService getCustomService() {
        return getService(CustomService.class);
    }

}

interface CustomService {
    @GET("/1.1/followers/list.json")
    void show(@Query("user_id") Long userId, @Query("screen_name") String
            var, @Query("skip_status") Boolean var1, @Query("include_user_entities") Boolean var2, @Query("count") Integer var3, Callback<Followers> cb);
}

My Error log are following :

   java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=140, result=-1, data=Intent { (has extras) }} to activity {com.app.SocialIntegrationFragment}: java.lang.IllegalArgumentException: Service methods cannot return void.
                                                             for method CustomService.show
                                                             at android.app.ActivityThread.deliverResults(ActivityThread.java:3319)
                                                             at android.app.ActivityThread.handleSendResult(ActivityThread.java:3362)
                                                             at android.app.ActivityThread.access$1100(ActivityThread.java:141)
                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1282)
                                                             at android.os.Handler.dispatchMessage(Handler.java:99)
                                                             at android.os.Looper.loop(Looper.java:137)
                                                             at android.app.ActivityThread.main(ActivityThread.java:5041)
                                                             at java.lang.reflect.Method.invokeNative(Native Method)
                                                             at java.lang.reflect.Method.invoke(Method.java:511)
                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
                                                             at dalvik.system.NativeStart.main(Native Method)
                                                          Caused by: java.lang.IllegalArgumentException: Service methods cannot return void.
                                                             for method CustomService.show
                                                             at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:695)
                                                             at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:686)
                                                             at retrofit2.ServiceMethod$Builder.createCallAdapter(ServiceMethod.java:227)
                                                             at retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:159)
                                                             at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:166)
                                                             at retrofit2.Retrofit$1.invoke(Retrofit.java:145)
                                                             at com.app.$Proxy8.show(Native Method)
                                                             at com.app.SocialIntegrationFragment$5$1.success(SocialIntegrationFragment.java:190)
                                                             at com.twitter.sdk.android.core.identity.TwitterAuthClient$CallbackWrapper.success(TwitterAuthClient.java:230)
                                                             at com.twitter.sdk.android.core.identity.AuthHandler.handleOnActivityResult(AuthHandler.java:92)
                                                             at com.twitter.sdk.android.core.identity.TwitterAuthClient.onActivityResult(TwitterAuthClient.java:161)
                                                             at com.app.SocialIntegrationFragment.onActivityResult(SocialIntegrationFragment.java:534)
                                                             at android.app.Activity.dispatchActivityResult(Activity.java:5293)
                                                             at android.app.ActivityThread.deliverResults(ActivityThread.java:3315)
                                                                ... 11 more

Please any one help me solveout this.

You should try this way

interface CustomService {
    @GET("/1.1/followers/list.json")
    Call<Followers> show(@Query("user_id") Long userId, @Query("screen_name") String
            var, @Query("skip_status") Boolean var1, @Query("include_user_entities") Boolean var2, @Query("count") Integer var3);
}

And

new MyTwitterApiClient(session).getCustomService().show(session.getId(), null, true, true, 100).enqueue(YOUR_CALLBACK);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM