Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParseUser.logInInBackground issue #710

Open
fuldevpok opened this issue Aug 17, 2017 · 9 comments
Open

ParseUser.logInInBackground issue #710

fuldevpok opened this issue Aug 17, 2017 · 9 comments

Comments

@fuldevpok
Copy link

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
Copy link
Contributor

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
Copy link
Author

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

@addisonElliott
Copy link
Contributor

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
Copy link
Author

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
Copy link
Author

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

@addisonElliott
Copy link
Contributor

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
Copy link
Author

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
Copy link
Contributor

addisonElliott commented Aug 17, 2017

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.

@yz
Copy link

yz commented Sep 8, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants