Parse-SDK-Android icon indicating copy to clipboard operation
Parse-SDK-Android copied to clipboard

ParseUser.logInInBackground issue

Open fuldevpok opened this issue 8 years ago • 9 comments

I'm developing an android app which use Parse login module and call ParseUser.logInInBackground. But a few days ago, it was working but now it don't work any more. When I tried to login, it returns user = null, exception = "com.parse.ParseRequest$ParseRequestException: i/o failure". Also the cause of this exception is "java.net.UnknownHostException: Unable to resolve host "xxx.herokuapp.com": No address associated with hostname". Also I've the iOS app which have same features, but iOS app work correctly. So this means that there is a bug on Parse-Android SDK. I checked server side but couldn't find anything about this problem.

fuldevpok avatar Aug 17 '17 11:08 fuldevpok

This is odd. So the exception UnknownHostException is telling me that the web server is not online.

As an additional test, open a command terminal and run: ping xxx.herokuapp.com

If it says request timed out, then that server URL is not valid...

addisonElliott avatar Aug 17 '17 11:08 addisonElliott

iOS app works correctly. So there is no problem on server.

fuldevpok avatar Aug 17 '17 11:08 fuldevpok

I completely understand that logically, since the iOS app works correctly then the server should be fine. But, can you humor me and do the ping just so we can get some additional details? I attempted to ping herokuapp.com and xxx.herokuapp.com and received a request timeout each time, so that is why I am suspecting that.

Also, can you try running your Android app on a few different devices. If you're using an emulator, try using your phone, one which you know the internet is working correctly.

Once you've tried those two approaches, the next step is probably implementing some OkHttp interceptors to see exactly which requests are being run and what they look like.

How to implement OkHttp Interceptors

Hopefully someday I can get some time to add this information to the docs, but for now I'll just give you a lowdown on how I've implemented it.

Add the class LoggingInterceptor to your project:

public class LoggingInterceptor implements Interceptor
{
    private static final String TAG = "LoggingInterceptor";

    @Override
    public Response intercept(@NonNull Interceptor.Chain chain) throws IOException
    {
        Request request = chain.request();

        long t1 = System.nanoTime();
        Log.i(TAG, String.format("Sending %s request %s on %s%n%s%n%s", request.method(),
                request.url(), chain.connection(), request.headers(),
                Util.requestBodyToString(request.body())));

        Response response = chain.proceed(request);

        long t2 = System.nanoTime();

        Log.i(TAG, String.format("Received response for %s in %.1fms%n%s", response.request().url(),
                (t2 - t1) / 1e6d, response.headers()));

        return response;
    }
}

Next, go to your custom Application class and add the following:

            OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
            clientBuilder.addInterceptor(new LoggingInterceptor());
            builder.clientBuilder(clientBuilder);

where builder is an instance of Parse.Configuration.Builder

addisonElliott avatar Aug 17 '17 11:08 addisonElliott

Just tested with ping on terminal and got request timed out. But maybe ping make security issues, so heroku will block this requests. But main point is iOS app works. Also thanks for your interceptor but I don't think this is the real solution for that. The reason is simple, because iOS think server url is valid but android not think like that?

fuldevpok avatar Aug 17 '17 11:08 fuldevpok

Also already tested with several devices and emulator. and the result is bad for me.

fuldevpok avatar Aug 17 '17 11:08 fuldevpok

Yeah, you're right about the ping for Heroku. I wasn't aware of this, so that is interesting.

The fact that this was working a few days ago is also interesting. Do you mind posting some sort of code, such as your Application class for Android and iOS?

I'm not sure how this could be a bug in the Parse Android SDK since the SDK just attempts to request information from the server and it is receiving an UnknownHostException. This problem sounds like an issue with configuration, network or something in between.

addisonElliott avatar Aug 17 '17 12:08 addisonElliott

Parse.Configuration conf = new Parse.Configuration.Builder(this) .applicationId(getString(R.string.parse_app_id)) .clientKey(getString(R.string.parse_client_key)) .server(getString(R.string.parse_url)) .build();

fuldevpok avatar Aug 17 '17 17:08 fuldevpok

Hm, pretty standard configuration. This is an odd issue.

I'm not sure if there is an easy way for me to reproduce this issue and further test it. However, I can give you some ideas on how to debug it.

  • Setup a basic local Parse server (clean) (or use back4app) and ONLY change the application ID, server and client key on Android project. If this works for Android (and your iOS) application, then that seems to suggest the server configuration is refusing the Android SDK for some reason.
  • If the error still persists on a basic local Parse server, then it seems to suggest a Parse SDK bug is present. I would comment out all unnecessary code and submit a simple test case for me to try and diagnose.

addisonElliott avatar Aug 17 '17 18:08 addisonElliott

@addisonElliott @fuldevpok Any solution to this? We are experiencing a similar login issue but it is strange that works on some devices and while others don't.

yz avatar Sep 08 '20 14:09 yz