Open Hans0002 opened 6 years ago
If have written a small test where I call the Spotify Web API directly. That works (Response Code = 200) for my user ID that has the "+" character:
public void jsonTestWithUserProfile(SpotifyApi api) throws IOException { String spotifyUsersAPI = "https://api.spotify.com/v1/users/"; String userID_UTF8 = URLEncoder.encode(Configuration.USER_ID, "UTF-8");
URL urlForSpotifyAPICall = new URL(spotifyUsersAPI + userID_UTF8);
HttpURLConnection conn = (HttpURLConnection) urlForSpotifyAPICall.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Authorization", "Bearer " + api.getAccessToken());
System.out.println("Response Code: " + conn.getResponseCode());
}
Thanks for the report @Hans0002, sorry it's taken us so long to reply. I'll ask the team.
I tried to use the "Java Spotify Web API" but with my spotify user ID that contains a "+" character it is not working. With other user IDs it works well.
For example if I want to get the user profile with "GetUsersProfileRequest" the user cannot be found. With "Spotify for Developers Web Console" it works well --> see: https://beta.developer.spotify.com/console/get-users-profile
The user ID with a "+" character for example "abc+xyz" will be converted to HTTP-conform version that contains the excaping String "%2B" that replaces the "+" character --> example curl command:
curl -X "GET" "https://api.spotify.com/v1/users/**abc%2Bxyz**" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer BQD8ebKdL-VPcSf4eWKxqBaQ0YF6v09EZvajlX7yznK8W0ZffI7vqW377Ulv3ebACiyNkKYsoDIoPkFDJSbovxhJuPHxNc9nPYrvhWQcnwpfeC1p1EOwcV7mFKDV_j2zjY-LzPVvV1zZbOBOFjagOEtUSmam_P2s0GB9H57przLCCvXCW9umHnmzxlI1N8F_GUFws2dlTcGStek6awIE"
I have seen that in the "Java Spotify Web API" in the class "AbstractRequest" in the method "setPathParameter" the value is encoded to "UTF-8":
encodedValue = URLEncoder.encode(value, "UTF-8");
This UTF-8 encoding leads to "abc%2Bxyz" too. So it should work. But maybe somewhere else in the code it is encoded again.
Do you have an idea what could be the reason why it does not work with user IDs with "+" character?