【问题标题】:Querying spotify web-api return 404查询 spotify web-api 返回 404
【发布时间】:2012-06-22 19:44:13
【问题描述】:

在我的 android 应用程序中,当我尝试解析 spotify web api 时,页面返回 404。URL 对我来说似乎没问题 (http://ws.spotify.com/search/1/album.xml?q =album:'Meteora'+artist:'Linkin Park'),但返回 404。

这是我的代码:

        url = new URL("http://ws.spotify.com/search/1/album.xml?q=album:'" + albumName + "'+artist:'" +artistName +"'");

        urlc = url.openConnection();
        urlc.addRequestProperty("User-Agent", userAgent);
        Log.v(TAG_SPOTIFY, "User-agent set: " + userAgent);
        return this.parseSpotifyURI(urlc.getInputStream());

这是错误:

06-20 16:51:00.846: W/System.err(4962): java.io.FileNotFoundException: http://ws.spotify.com/search/1/album.xml?q=album:'Meteora'+artist:'Linkin Park'
06-20 16:51:00.846: W/System.err(4962):     at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177)
06-20 16:51:00.846: W/System.err(4962):     at com.micky.scanthings.music.ParseMusic.getSpotifyURI(ParseMusic.java:489)
...

【问题讨论】:

    标签: android spotify asp.net-web-api


    【解决方案1】:

    好吧,我的错。我的 URL 没有以 UTF8 编码,因此 Spotify 以 404 响应。 解决方案是这样解析专辑名称和艺术家:

    String myURL = "album:'" + albumName + "'+artist:'" +artistName +"'";
    url = new URL("http://ws.spotify.com/search/1/album.xml?q=" + URLEncoder.encode(myURL,"UTF-8"));
    

    然后对这个 URL 做任何我们想做的事情。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-07
      • 1970-01-01
      • 2022-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-15
      相关资源
      最近更新 更多