Spotify API 的响应中缺少“发布者”字段

Spotify API is missing the "publisher" field in its response

提问人:stneric 提问时间:6/12/2023 更新时间:6/12/2023 访问量:20

问:

我现在正在为 uni 做一个项目,我需要对 Android 应用程序的 Spotify API 进行 API 调用。一切都按预期进行,并没有给我带来太多麻烦,但由于某种原因,Spotify 回复中的“发布者”字段是空的。

我尝试手动将其设置为不可为空,但这只会使应用程序崩溃,因为它没有被传输。

Spotify API 文档还指出,该字段应存在于响应中。 (https://developer.spotify.com/documentation/web-api/reference/get-a-show)

这是我的代码(带有 Gradle 的 Kotlin):

@Composable
fun DisplayPodcastInfo(podcastLink: String, spotifyAccessToken: String) {
    var podcastInfo by remember { mutableStateOf<PodcastInfo?>(null) }

    //because no episode can be pulled with a request, need to pull all and search for the requested one
    val showId: String
    val episodeId: String

    if (podcastLink.contains("/show/")) {
        showId = podcastLink.substringAfter("/show/").substringBefore("?", "")
        episodeId = ""
    } else if (podcastLink.contains("/episode/")) {
        episodeId = podcastLink.substringAfter("/episode/").substringBefore("?", "")
        showId = ""
    } else {
        Log.e("PodcastInfo", "Invalid podcast link: $podcastLink")
        return
    }

    if (episodeId.isNotEmpty()) {
        LaunchedEffect(episodeId) {
            val httpClient = HttpClient {
                install(JsonFeature) {
                    serializer = KotlinxSerializer(json = kotlinx.serialization.json.Json { ignoreUnknownKeys = true })
                }
            }

            //building the request
            val episode: PodcastInfo = httpClient.get("https://api.spotify.com/v1/episodes/$episodeId") {
                headers {
                    append("Authorization", "Bearer $spotifyAccessToken")
                }
                parameter("market", "DE")
            }

            podcastInfo = episode
            Log.w("Spotify API Res", "Response: \n $episode")
        }

    } else if (showId.isNotEmpty()) {
        Log.e("PodcastInfo", "invalid link, $podcastLink the podcast link might be the $podcastInfo")
    } else {
       Log.e("PodcastInfo", "Invalid podcast link: $podcastLink")
   }...

这是我用来解析响应的数据结构:

@Serializable
data class PodcastInfo(
    val audio_preview_url: String? = null,
    val description: String? = null,
    val duration_ms: Float? = null,
    val explicit: Boolean? = null,
    val name: String,
    val publisher: String? = null,
    val images: List<SpotifyImage>,
    val id: String,
    val uri: String? = null
)

(请注意,我正在使用“ignoreUnknownKeys = true”可安装文件以避免必须扩展我的 PodcastInfo 类)

我不知道这是怎么回事。

我尝试了几个不同的播客,“publisher: String”(使应用程序崩溃),但它仍然没有得到值。

JSON API Kotlin 序列化 Spotify

评论

0赞 Ximzend 6/12/2023
我已经测试了显示 ID 的终结点,它显示发布者没有问题。

答: 暂无答案