mimicmobile/okhttp-oauth2-client

NetworkOnMainThreadException

blennerSilva opened this issue · 1 comments

Why am i getting this ?

here is an example of my call

new Handler().postDelayed(new Runnable() {
public void run() {

                    OAuth2Client client = new OAuth2Client.Builder("8", "", "10399857", "6m3KNklmavo3g", "https:token").grantType("password").scope("Identity").build();
                    OAuthResponse response = null;
                    try {
                        response = client.requestAccessToken();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    if (response.isSuccessful()) {
                        String accessToken = response.getAccessToken();
                        String refreshToken = response.getRefreshToken();
                    } else {
                        OAuthError error = response.getOAuthError();
                        String errorMsg = error.getError();
                    }

                    response.getCode();
                }
            }, 100);
        }

Requests need to be made on a non-UI thread, or you need to use the callbacks.