I am trying to read the data from a google sheet with retrofit2, but when accessing it, it is throwing me this error:
Caused by: java.lang.IllegalArgumentException: baseUrl must end in /: https://sheets.googleapis.com/v4/spreadsheets/12f8EEM27sdx_-nqmyUbciSQpdfoVqgrgSrsCkeXT7S8/values/BASE!A1:D?key=AIzaSyAJz5cv2JOo6GjJAxhvy_B5H2t472UTQw4
From what I've read, it's because of a "/" at the end of the URL, but if I add it, it gives me the same error.
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://sheets.googleapis.com/v4/spreadsheets/12f8EEM27sdx_-nqmyUbciSQpdfoVqgrgSrsCkeXT7S8/values/BASE!A1:D?key=AIzaSyAJz5cv2JOo6GjJAxhvy_B5H2t472UTQw4")
.addConverterFactory(GsonConverterFactory.create())
.build();
this is my interface
import com.example.formsaide.Entidades.Codigos;
import java.util.List;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Path;
public interface JsonPlaceHolderApi {
@GET("posts") //indica el metodo de acceso ala URL
Call<List<Codigos>> getCodigos();
}
Could someone tell me what I can do, thanks.
The error message indicates the problem:
When defining the base url of the API you must use a url that must end with the "/" character, instead you are defining a base url that does not have this value, it should be:
according to the documentation the base url should be:
and in the interface that you define as data source is where the resource is defined, it is an example:
I suggest you review your implementation, this is an example of an API request using Retrofit:
GOOGLE SPREADSHEETS AS A DATA SOURCE FOR AN ANDROID APP USING RETROFIT