No way to create a project without the TwitterLoginButton on Android

android
twitterkit

#1

I have followed all the tutorials about Twitter login without TwitterLoginButton , but nothing works.

This is my app class:

public class App extends Application {

@Override
public void onCreate() {
    super.onCreate();
    final String TWITTER_KEY = "123";
    final String TWITTER_SECRET = "123";
    TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
    Fabric.with(this, new Twitter(authConfig));
}

My activity

    TwitterAuthClient mTwitterClient = new TwitterAuthClient();
    mTwitterClient.authorize(MainActivity.this, new Callback<TwitterSession>() {
        @Override
        public void success(Result<TwitterSession> result) {
            Log.d(Constans.LOG, "login_succes");
            
            TwitterSession session = Twitter.getSessionManager().getActiveSession();
            Twitter.getSessionManager().setActiveSession(session);
            TwitterAuthToken authToken = session.getAuthToken();
            final String token = authToken.token;
        }
        @Override
        public void failure(TwitterException exception) {
            Log.d(Constans.LOG, "login_err " + exception.getMessage());
        }
    });

My ActivityResult

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(Constans.LOG,“On activity result called”);
mTwitterAuthClient= new TwitterAuthClient();
mTwitterAuthClient.onActivityResult(requestCode, resultCode, data);
}

The error itself

Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:387)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:209)
at com.twitter.sdk.android.core.models.SafeListAdapter$1.read(SafeListAdapter.java:45)
at com.twitter.sdk.android.core.models.SafeMapAdapter$1.read(SafeMapAdapter.java:45)
at com.google.gson.Gson.fromJson(Gson.java:879)
at com.google.gson.Gson.fromJson(Gson.java:844)
at com.google.gson.Gson.fromJson(Gson.java:793)
at com.google.gson.Gson.fromJson(Gson.java:765)
at com.twitter.sdk.android.core.TwitterApiException.parseApiError(TwitterApiException.java:111)
at com.twitter.sdk.android.core.TwitterApiException.readApiError(TwitterApiException.java:96)
at com.twitter.sdk.android.core.TwitterApiException.(TwitterApiException.java:44)
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:5254)
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:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

Failed to get request token
com.twitter.sdk.android.core.TwitterApiException: HTTP request failed, Status: 401
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:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

My customer
:rage:

and I
:scream:


#2

Happy to help @postllisas - can you share which version of Fabric and TwitterKit you’re using?


#3

Hello @bonnell , thanks a lot for your support.

com.twitter.sdk.android:twitter:2.2.0@aar’


#4

Thanks for confirming, let me do some local testing and I’ll get back to you!