9

最近我遇到了 Last.fm API 的问题,我有一个功能齐全的代码,该代码在 2/3 天前工作,但今天每次尝试从 API 获取艺术家图片都会返回一个数组,所有艺术家的所有图像尺寸都具有相同的 url。灰色背景白色星形图像。我尝试使用新的 API 密钥创建另一个帐户,以检查我的密钥是否有问题,自从我上次更新 API 相关代码以来已经有几个月了,但没有成功。

这是代码

    private static final String BASE_URL = "http://ws.audioscrobbler.com/2.0/";
private static final String API_KEY = "123456789";

@Nullable
public static String fetchJson(String url) {


    HttpURLConnection urlConnection = null;
    StringBuilder mStringBuilder = new StringBuilder();

    try {
        urlConnection = (HttpURLConnection) new URL(url).openConnection();

        InputStream mInputStream = new BufferedInputStream(urlConnection.getInputStream());
        BufferedReader mReader = new BufferedReader(new InputStreamReader(mInputStream));

        String line;
        while ((line = mReader.readLine()) != null) {
            mStringBuilder.append(line);
        }

        return mStringBuilder.toString();

    } catch (Exception e) {

        e.printStackTrace();
        return null;

    } finally {
        if (urlConnection != null) urlConnection.disconnect();
    }
}



public static String createArtistURL(String artistName) {
    artistName = artistName.replace("&", "%26");
    // TODO: 03/05/2019  testar isso  URLEncoder.encode(artistName,UTF?); 
    return BASE_URL.concat("?method=artist.getinfo")
            .concat("&artist=").concat(artistName)
            .concat("&lang=").concat(Locale.getDefault().getLanguage())
            .concat("&api_key=").concat(API_KEY)
            .concat("&format=json");
      }
4

2 回答 2

5

不幸的是,这是Last.fm 方面的故意更改

我们已根据我们的 API 使用条款对 API 进行了更改,以限制滥用行为并为所有人改进服务。

虽然我们允许 API 用户通过 API 访问大量数据,但第三方使用音频、视听、图像或艺术品始终违反我们的 API 使用条款。在某些情况下,一些数据可能可以通过少量 API 调用间接访问,因此作为最近 API 清理的一部分,我们已经纠正了这种异常情况。

如果您的应用程序受到影响,请参阅我们的 API 使用条款以确保您的合规性。

艺术家图像的替代 API 来自 MusicBrainz。如果您正在处理 Last.fm 数据,您可能已经拥有艺术家的 MBID,您可以像这样查询它(JavaScript 示例):

于 2019-12-30T10:58:35.167 回答
5

我只能提供一个无用的“我也是”。希望这只是一个错误,而不是 LFM 发布灾难性公告的前兆……

于 2019-05-04T04:43:26.987 回答