Volley Android - GET to return list of videos from a playlist - JAVA

Asked

Viewed 50 times

1

Hello, I’m using the android library Volley to make a GET call (https) to return to me the Json of the videos of a specific playlist. Basically my current GET request is this:

String url ="https://youtube.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=PLl-K7zZEsYLlRjj-mSComCq3Vd4IJese1&key="+YoutubeConfig.getApiKey();

Where YoutubeConfig.getApiKey(); is my API key created on the developer console with AUTH 2.0 key and registered in the application’s SHA-1.

When trying to do GET in the solution, the code returns me an Errorresponse and "null" as message code, like this:


        // Instantiate the RequestQueue.
        RequestQueue queue = Volley.newRequestQueue(this);
        String url ="https://youtube.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=PLl-K7zZEsYLlRjj-mSComCq3Vd4IJese1&key="+YoutubeConfig.getApiKey();

        // Request a string response from the provided URL.
        StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        // Display the first 500 characters of the response string.
                        Log.i("onResponse", "onResponse: "+response);
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.i("ErrorOnResponse", "onErrorResponse: "+error.getLocalizedMessage());
            }
        });

        // Add the request to the RequestQueue.
        queue.add(stringRequest);

logCat:

2020-11-17 10:04:22.256 23662-23662/com.appX.a2f20 I/ErrorOnResponse: onErrorResponse: null

That is, the GET request could not be validated, I’m not understanding why, the format seems to me to be correct and the playlistID is valid, someone knows why this error happens?

1 answer

1

I was able to solve, the code of Sponse that was returning was 403-Forbidden

Translating basically to that my API key had no access to the Youtube API of HTTP requests. What I did?

I went to my Google Apis console and added in my "Libraries" the Youtube Data API library V3, adding it to my existing project, after that, I could go into my API key used in the App and insert into the constraint the Youtube Data API v3 library that was now eligible to be selected (as it had not been added in the libraries it was not displayed before, so I thought it was not necessary).

Now the GET request works well and returns me the Json correctly. I think the biggest problem is not in the Volley library, but in Google’s lack of clarity in the documentation when talking about which libraries should be added to the project so that they are displayed in the API restrictions.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.