0
我正在構建一個Android應用程序,我在其中使用通過Mashape市場的Internet遊戲數據庫API。我正在使用Retrofit獲取請求,並從API獲取數據需要API密鑰。使用Retrofit添加字段到URL
我得到它的工作,但API只返回遊戲ID和我想要的遊戲名稱和其他信息,但我不知道如何添加字段。這是Mashape如何查詢它:
HttpResponse<String> response = Unirest.get("https://igdbcom-internet-game-database-v1.p.mashape.com/games/?fields=name%2Crelease_dates")
.header("X-Mashape-Key", "API KEY HERE")
.header("Accept", "application/json")
.asString();
,這是我更新接口
public interface GamesAPIService {
@GET("/games/")
Call<List<GamesResponse>> gameList(@Query("mashape-key") String apikey);
}
我試圖用這個
@GET("/games/?fields=name,release_dates")
,但沒有運氣,我也試圖與@Field但也沒有工作。有任何想法嗎?謝謝。
編輯:只是爲了澄清當我添加"?fields=name,release_dates"
我得到401未經授權的錯誤。
爲什麼你有'@Query(「mashape-key」)String apikey'?您在URL中沒有'?mashape-key = ...'...關鍵需要是標題,而不是查詢參數。 –
我試過@Header來傳遞apikey,或者在作爲「.addHeader」的活動本身中,它從來沒有工作過,但是它出於某種原因這樣工作,所以我保留了它。 – Prime47