0
有幾個關於stackoverflow的問題,就像我一樣,但我一直無法解決我的問題。錯誤如標題所述。我正在使用Spotify API獲取。我覺得我對發生的事情有一個基本的誤解。
下面是我在我的主要活動:
Gson gson1 = new GsonBuilder()
.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
.setLenient()
.create();
Retrofit retrofit1 = new Retrofit.Builder()
.baseUrl(ENDPOINT_ACCOUNTS)
.addConverterFactory(GsonConverterFactory.create(gson1))
.build();
SpotifyAPI spotifyAPI = retrofit1.create(SpotifyAPI.class);
Call<User> call1 = spotifyAPI.getUserData("Authorization: Bearer " + sp.getString("accessCode", "DEFAULT"));
call1.enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
...
}
@Override
public void onFailure(Call call, Throwable t) {
...
}
});
這裏是我的接口:
String ENDPOINT_V1 = "https://api.spotify.com/";
@GET("/v1/me")
Call<User> getUserData(@Header("Authorization") String authorization);
這裏是我的用戶等級:
public class User {
String id;
public String toString() {
return(id);
}
}
onFailure處()是被觸發,吐出標題中的錯誤信息。如果我將用戶的所有實例都替換爲ResponseBody,則該調用將成功,狀態碼爲200.但響應的內容完全不是我想要的。請讓我知道,如果有更多的信息我可以提供。謝謝。