SweetzpotAS / StravaZpot-Android

A fluent API to integrate with Strava on Android apps
70 stars 35 forks source link

Issues with Getting Segments #5

Closed jippylong12 closed 7 years ago

jippylong12 commented 7 years ago

I am trying to access the Segments part of the API, specifically the exploreSegementsInRegion, and I believe I have it set up correctly, but I am getting an error as such:

java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $

As far as I know, it is not an issue with my code. Really all I have so far is what is shown in the Readme(which is well done by the way).

I know that I get back a response because I can see it in Android Monitor, but I think when it is trying to convert it to the List it is throwing an error.

The boyd of my function looks like this

      try {
            AuthenticationConfig config = AuthenticationConfig.create()
                    .debug()
                    .build();
            AuthenticationAPI api = new AuthenticationAPI(config);
            TOKEN = api.getTokenForApp(AppCredentials.with(Integer.parseInt(getString(R.string.clientID)), getString(R.string.clientSecret)))
                    .withCode(CODE)
                    .execute();

            CONFIG = StravaConfig.withToken(TOKEN.getToken())
                    .debug()
                    .build();

            SegmentAPI segmentAPI = new SegmentAPI(CONFIG);
            segments = segmentAPI.exploreSegmentsInRegion(Bounds.with(Coordinates.at(SW_LAT, SW_LONG), Coordinates.at(NE_LAT, NE_LONG)))
                    .forActivityType(ExploreType.RIDING)
                    .execute();
            System.out.println("here");

        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

That code is in the doInBackground section of an AsyncTask, but I again I believe that is all correct to my knowledge.

The first three lines of the traceback are:

at com.google.gson.stream.JsonReader.beginArray(JsonReader.java:350) at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:80) at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)

Let me know if you need anymore information and thank you.

truizlop commented 7 years ago

Hi @jippylong12,

Thanks for using StravaZpot. It would be helpful for us if you paste here the JSON you are receiving from Strava. You can look for it in the LogCat. It seems there is some case where an array is expected, but the contents of the JSON is a single object; therefore, it crashes. Let us know and we'll fix the issue.

jippylong12 commented 7 years ago

I have attached the response I am getting. Thank you. stravaError.txt

truizlop commented 7 years ago

The issue has been fixed and a new library version (1.1.3) has been published. Please, update your Gradle file to get this new version and see if everything has been solved. If so, you can close the issue. Let us know if you face any other issue and thanks for contributing!

jippylong12 commented 7 years ago

Thanks for the quick turn around! It works!