parse-community / Parse-SDK-Android

The Android SDK for Parse Platform
https://parseplatform.org/
Other
1.89k stars 735 forks source link

ParseUser.logInInBackground issue #710

Open fuldevpok opened 7 years ago

fuldevpok commented 7 years ago

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.

addisonElliott commented 7 years ago

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...

fuldevpok commented 7 years ago

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

addisonElliott commented 7 years ago

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

fuldevpok commented 7 years ago

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 commented 7 years ago

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

addisonElliott commented 7 years ago

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.

fuldevpok commented 7 years ago

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();

addisonElliott commented 7 years ago

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.

yz commented 4 years ago

@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.