Announcements

Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

Get an artist genre on Android Studio

Solved!

Get an artist genre on Android Studio

Plan

Free/Premium

Country

France

 

My Question or Issue

Hi everyone, I'm here to ask a question, I would like to get an artist genre on android studio with the spotify sdk but when I went on the documentation no field contained the genre of the artist. I know that with spotify web api with a get request we can get in the json file the genre. So I tried to made a get request on my android app with the token of the user auth on the project but it didn't work. So if someone knows how can I get it, it would be nice.   Have a nice day.

Reply

Accepted Solutions
Marked as solution

Sorry I had to send it quickly yesterday :

 

    public void artistRequest(String token){
        OkHttpClient client = new OkHttpClient();

  

            Request request = new Request.Builder()
                    .addHeader("Authorization","Basic : "+encodedInput)
                    .url("https://api.spotify.com/v1/artists/41X1TR6hrK8Q2ZCpp2EqCz")
                    .addHeader("Authorization","Bearer "+token)
                    .addHeader("Accept","application/json")
                    .addHeader("Content-Type","application/json")
                    .build();

        Response response = null;
        try {
            response = client.newCall(request).execute();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Log.i("DEBUG GET CODE  : ", String.valueOf(response.code()));
        Log.i("DEBUG GET CODE  : ", response.message());
    }

 

I call this method async from the main ui thread, with the access token that spotify api sent me thank to the authorization library for android studio. And maybe it doesn't work because token from authorization library is not compatible with request from spotify web api ? Don't know

View solution in original post

6 Replies

but it didn't work

You have to be more specific than that. The access token returned by the iOS SDK can be used with the web API, so I assume the same applies to the Android SDK. Does the access token work with any web API Endpoints?

Yes sorry, it didn't work, I tried a get request with okhttp to get the
artist json response but i got 403 error forbidden, so as you said, the
token is recognized but It didn't work.

Show me the code where you make the request to the Spotify web API.

here you go

Capture.PNG

Don't ever post a screenshot of code. Always post it as text so that someone else can copy and paste it and run it themselves.

Marked as solution

Sorry I had to send it quickly yesterday :

 

    public void artistRequest(String token){
        OkHttpClient client = new OkHttpClient();

  

            Request request = new Request.Builder()
                    .addHeader("Authorization","Basic : "+encodedInput)
                    .url("https://api.spotify.com/v1/artists/41X1TR6hrK8Q2ZCpp2EqCz")
                    .addHeader("Authorization","Bearer "+token)
                    .addHeader("Accept","application/json")
                    .addHeader("Content-Type","application/json")
                    .build();

        Response response = null;
        try {
            response = client.newCall(request).execute();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Log.i("DEBUG GET CODE  : ", String.valueOf(response.code()));
        Log.i("DEBUG GET CODE  : ", response.message());
    }

 

I call this method async from the main ui thread, with the access token that spotify api sent me thank to the authorization library for android studio. And maybe it doesn't work because token from authorization library is not compatible with request from spotify web api ? Don't know

Suggested posts