首页 > 解决方案 > 无法更改 Spotify API(顶级艺术家)的默认限制 - React Native

问题描述

我已经尝试了一切来改变这一点……不知道出了什么问题,无论如何它仍然只是把 20 位艺术家拉回来。

const sp = await this.getValidSPObj();
const { id: userId } = await sp.getMe();
const { items: topArtists } = await sp.getMyTopArtists(userId, {limit: 10, offset: 20});
this.props.setData("TopArtists", topArtists);

来自 API 的注释...

/**
 * Get the current user’s top artists based on calculated affinity.
 * See [Get a User’s Top Artists](https://developer.spotify.com/web-api/get-users-top-artists-and-tracks/) on
 * the Spotify Developer site for more information about the endpoint.
 *
 * @param {Object} options A JSON object with options that can be passed
 * @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first
 * one is the error object (null if no error), and the second is the value if the request succeeded.
 * @return {Object} Null if a callback is provided, a `Promise` object otherwise
 */
getMyTopArtists(
  options?: Object,
  callback?: ResultsCallback<SpotifyApi.UsersTopArtistsResponse>
): Promise<SpotifyApi.UsersTopArtistsResponse>;

标签: reactjsapinativespotify

解决方案


根据函数signature没有standalone参数userID,您userID作为first参数传递,实际上first参数是options对象!

文档还提到有些functions不需要userIDhttps ://github.com/JMPerez/spotify-web-api-js#getting-users-information

有些函数不需要接收用户的 id 作为参数,会使用访问令牌中的用户信息:<code_example>

ps:我相信根据你的access_tokenscope它会计算出用户。


推荐阅读