【问题标题】:Foursquare API get venue details with Retrofit for AndroidFoursquare API 使用 Retrofit for Android 获取场地详细信息
【发布时间】:2019-07-08 08:24:54
【问题描述】:

我是 Retrofit for Android 的新手,想知道如何在想获取场地详细信息时提出正确的请求 (https://developer.foursquare.com/docs/api/venues/details)

我知道如何提出这样的请求:https://api.foursquare.com/v2/venues/search&v=20190211&near=Amsterdam

@GET("/v2/venues/search")
fun getVenueResults(
    @Query("near") near: String,
    @Query("limit") limit: Int,
    @Query("v") version: Int = 20190211,
    @Query("client_id") clientId: String = BuildConfig.FS_Client_ID,
    @Query("client_secret") clientSecret: String = BuildConfig.FS_Client_Secret
): Call<FoursquareAPIResponse>

但对于详细信息,您必须向以下地址提出获取请求:

https://api.foursquare.com/v2/venues/VENUE_ID

其中 VENUE_ID 是场地的 ID。如果我这样做:

@GET("/v2/venues/")
fun getVenueDetails(
    @Query("") id: String,
    @Query("v") version: Int = 20190211,
    @Query("client_id") clientId: String = BuildConfig.FS_Client_ID,
    @Query("client_secret") clientSecret: String = BuildConfig.FS_Client_Secret
): Call<FoursquareAPIResponse>

它使用场所/?=VENUE_ID 而不是场所/VENUE_ID 格式化获取请求

有人可以帮助我在 Retrofit 中找到正确的方法来格式化获取场地/VENUE_ID 的请求吗?

【问题讨论】:

    标签: android retrofit2 foursquare get-request


    【解决方案1】:

    试试这个

    @GET("/v2/venues/{venueId}")
    fun getVenueDetails(
        @Query("v") version: Int = 20190211,
        @Query("client_id") clientId: String = BuildConfig.FS_Client_ID,
        @Query("client_secret") clientSecret: String = BuildConfig.FS_Client_Secret,
        @Path("venueId") id: String,
    ): Call<FoursquareAPIResponse>
    

    文档 - https://square.github.io/retrofit/2.x/retrofit/index.html?retrofit2/http/Path.html

    【讨论】:

    • 谢谢,我已经在玩@Path,但这个解决方案更干净。
    • 很高兴我能提供帮助。如果此解决方案对您有用,您可以将其标记为正确答案。干杯
    • 我已经尝试过了,但是我倒计时了 1 分钟,我现在接受了你的回答。干杯!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多