百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

spotify-web-api-android

> 编程语言
开源

Spotify Web API 的封装类。它使用 Retrofit 从 API 端点创建 Java 接口

377 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

Spotify Web API 的封装类。它使用 Retrofit 从 API 端点创建 Java 接口

Spotify Web API for Android

This project is a wrapper for the Spotify Web API. It uses Retrofit to create Java interfaces from API endpoints.

Integrating into your project

This library is available in JitPack.io repository. To use it make sure that repository's url is added to the build.gradle file in your app:

groovy
repositories {
    mavenCentral()
    maven { url "https://jitpack.io" }
}

dependencies {
    compile 'com.github.kaaes:spotify-web-api-android:0.4.1'

    // Other dependencies your app might use
}

Building

This project is built using Gradle:

  1. Clone the repository: git clone https://github.com/kaaes/spotify-web-api-android.git
  2. Build: ./gradlew assemble
  3. Grab the aar that can be found in spotify-api/build/outputs/aar/spotify-web-api-android-0.4.1.aar

Usage

Out of the box it uses OkHttp HTTP client and a single thread executor.

…

It is also possible to construct the adapter with custom parameters.

java
final String accessToken = "myAccessToken";

RestAdapter restAdapter = new RestAdapter.Builder()
        .setEndpoint(SpotifyApi.SPOTIFY_WEB_API_ENDPOINT)
        .setRequestInterceptor(new RequestInterceptor() {
            @Override
            public void intercept(RequestFacade request) {
                request.addHeader("Authorization", "Bearer " + accessToken);
            }
        })
        .build();

SpotifyService spotify = restAdapter.create(SpotifyService.class);

Obtaining Access Tokens

The most straightforward way to get the access token is to use the Authentication Library from the Spotify Android SDK. Detailed information how to use it can be found in the Spotify Android SDK Authentication Guide.

Feeling adventurous? You can implement the auth flow yourself, following the Spotify Authorization Guide.

Error Handling

When using Retrofit, errors are returned as RetrofitError objects. These objects, among others, contain HTTP status codes and their descriptions, for example 400 - Bad Request. In many cases this will work well enough but in some cases Spotify Web API returns more detailed information, for example 400 - No search query.

To use the data returned in the response from the Web API SpotifyCallback object should be passed to the request method instead of regular Retrofit's Callback:

java
spotify.getMySavedTracks(new SpotifyCallback>() {
    @Override
    public void success(Pager savedTrackPager, Response response) {
        // handle successful response
    }

    @Override
    public void failure(SpotifyError error) {
        // handle error
    }
});

For synchronous requests RetrofitError can be converted to SpotifyError if needed:

java
try {
    Pager mySavedTracks = spotify.getMySavedTracks();
} catch (RetrofitError error) {
    SpotifyError spotifyError = SpotifyError.fromRetrofitError(error);
    // handle error
}

Help

Versioning policy

We use Semantic Versioning 2.0.0 as our versioning policy.

Bugs, Feature requests

Found a bug? Something that's missing? Feedback is an important part of improving the project, so please open an issue.

Code

Fork this project and start working on your own feature branch. When you're done, send a Pull Request to have your suggested changes merged into the master branch by the project's collaborators. Read more about the GitHub flow.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Java

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言