skip to Main Content

I want to get the data using twitter’s fabric api but whenever i tend to verify credentials and use a callback it shows an error , specifically ,”The arguments differ in length”

void getUserData() {
        Twitter.getApiClient(session).getAccountService()
                .verifyCredentials(true, false, new Callback<User>() {

                    @Override
                    public void failure(TwitterException e) {

                    }

                    @Override
                    public void success(Result<User> userResult) {

                        User user = userResult.data;
                        String twitterImage = user.profileImageUrl;

                        try {
                            Log.d("imageurl", user.profileImageUrl);
                            Log.d("name", user.name);
                            Log.d("email",user.email);
                            Log.d("des", user.description);
                            Log.d("followers ", String.valueOf(user.followersCount));
                            Log.d("createdAt", user.createdAt);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }


                    }

                });


    }

2

Answers


  1. Just change the twitter dependency in your Build.Gradle
    from

    compile('com.twitter.sdk.android:twitter:2.0.0@aar') {
        transitive = true;
    }
    

    to

    compile('com.twitter.sdk.android:twitter:1.11.0@aar') {
        transitive = true;
    }
    

    The new version of the .verifyCredentials() method doesn’t accept a callback hence your error.

    Login or Signup to reply.
  2. If you check the fabric documentation, it shows two version of the method, however when I tried to open the source code in Android Studio but it had only the version without the callback.

    You can solve the isssue as follows:

    //Getting the account service of the user logged in
    Call<User> call = Twitter.getApiClient(session).getAccountService()
            .verifyCredentials(true, false);
    call.enqueue(new Callback<User>() {
            @Override
            public void failure(TwitterException e) {
                //If any error occurs handle it here
            }
            @Override
            public void success(Result<User> userResult) {
                //If it succeeds creating a User object from userResult.data
                User user = userResult.data;
                        String twitterImage = user.profileImageUrl;
    
                        try {
                            Log.d("imageurl", user.profileImageUrl);
                            Log.d("name", user.name);
                            Log.d("email",user.email);
                            Log.d("des", user.description);
                            Log.d("followers ", String.valueOf(user.followersCount));
                            Log.d("createdAt", user.createdAt);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
            }
        });
    

    Source

    Documentation

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search