How to use Guest Authentication in Android? - No Callback Method is called

android
auth
guest

#1

I can’t get Guest Authentication to work. Here is what I’m doing:

Created a new Project in Android Studio with Fabric Plugin. Codesnippets from my MainActivity:

private TwitterApiClient twitterApiClient;

@Override
protected void onCreate(Bundle savedInstanceState) {
  ...  
  TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
  Fabric.with(this, new Twitter(authConfig));
  ...
  twitterApiClient = getTwitterApiClient();
}


public TwitterApiClient getTwitterApiClient() {
    TwitterCore.getInstance().logInGuest(new Callback<AppSession>() {
        @Override
        public void success(Result<AppSession> result) {
            Log.d(Statics.TAG, "loginGuest.callback.success called");
            AppSession guestAppSession = result.data;
            twitterApiClient = TwitterCore.getInstance().getApiClient(guestAppSession);
        }

        @Override
        public void failure(TwitterException exception) {
            Log.d(Statics.TAG, "loginGuest.callback.failure called");
            // unable to get an AppSession with guest auth
            throw exception;
        }
    });

    return twitterApiClient;
}

When I debug my app, I see that no callback is called, neither success nor failure - and twitterApiClient is always null. Did someone get Guest Authentication in Android to work? So how?

Currently the following Versions are used:
com.twitter.sdk.android:twitter:1.8.0
±-- io.fabric.sdk.android:fabric:1.3.5

Would appreciate any tips!
Best, Thorsten


#2

ok i solved it. TwitterCore.getInstance().logInGuest is asynchronous. So of course, the twitterApiClient member isn’t set in my synchronous getTwitterApiClient call, but later on, when the callback is called.


#3