{"id":15146104,"url":"https://github.com/vpaliy/soundcloud-api","last_synced_at":"2025-07-04T07:38:05.337Z","repository":{"id":41445888,"uuid":"99622666","full_name":"vpaliy/SoundCloud-API","owner":"vpaliy","description":"SoundCloud API wrapped into a bunch of classes. Built with Retrofit2 and RxJava2.","archived":false,"fork":false,"pushed_at":"2021-05-07T18:20:43.000Z","size":251,"stargazers_count":69,"open_issues_count":2,"forks_count":17,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-01-30T22:09:51.548Z","etag":null,"topics":["api-wrapper","oauth2","retrofit2","rxjava2-retrofit2","soundcloud","soundcloud-api","wrapper"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vpaliy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-07T21:37:59.000Z","updated_at":"2024-05-04T08:18:14.000Z","dependencies_parsed_at":"2022-08-25T13:31:09.557Z","dependency_job_id":null,"html_url":"https://github.com/vpaliy/SoundCloud-API","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vpaliy%2FSoundCloud-API","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vpaliy%2FSoundCloud-API/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vpaliy%2FSoundCloud-API/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vpaliy%2FSoundCloud-API/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vpaliy","download_url":"https://codeload.github.com/vpaliy/SoundCloud-API/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237896892,"owners_count":19383604,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-wrapper","oauth2","retrofit2","rxjava2-retrofit2","soundcloud","soundcloud-api","wrapper"],"created_at":"2024-09-26T12:00:55.560Z","updated_at":"2025-02-09T02:32:16.505Z","avatar_url":"https://github.com/vpaliy.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SoundCloud-API for Android.\n[![](https://jitpack.io/v/vpaliyX/SoundCloud-API.svg)](https://jitpack.io/#vpaliyX/SoundCloud-API)\n\nThis project is a wrapper for the [SoundCloud API](https://developers.soundcloud.com/).\n\nThe SoundCloud API exposes SoundCloud resources like *tracks*, *playlists*, *users*, *comments*, etc.\nThe API gives you the ability to access a **sound's stream URL** and use your own player to play sounds from SoundCloud.\n\nThis repository uses Retrofit2 to create Java interfaces from API endpoints. It returns a `Single` which makes it very easy \nto handle asynchronous operations and you can convert an existing data structure into another Single . Please, refer to [Single Utility Operators](http://reactivex.io/documentation/single.html) for more details.  \n\n## How do I use this wrapper? ##\n\n### Step 1 ###  \n\nAdd this to your root `build.gradle` file:\n\n``` gradle\nallprojects {\n  repositories {\n     maven { url 'https://jitpack.io' }\n  }\n}\n```\n### Step 2 ###\n\nAdd the dependency\n\n``` gradle\ndependencies {\n\tcompile 'com.github.vpaliyX:SoundCloud-API:-SNAPSHOT'\n}\n\n```\n\n### Making Request ###\nYou need to get your `client_id` and `client_secret` by registering your app [here](https://developers.soundcloud.com/docs/api/guide). After you have obtained that, you can start using the API.\n\n\nBasically, most of the calls will look like this one:\n\n```java\nfinal SoundCloud api = new SoundCloud.Builder(context, Config.CLIENT_ID)\n\t.setToken(token)\n\t.setInterceptor(interceptor)\n\t.build();\nfinal SoundCloudService service = api.getSoundCloudService();\nservice.fetchTrack(\"123456678\") //some dummy track id\n\t.subscribeOn(Schedulers.io())\n        .observeOn(AndroidSchedulers.mainThread())\n        .subscribe(track-\u003e{\n        \t//do something with the track   \n \t});\n\t\n```\n\nIt's pretty simple. If you want to pass query paramaters, use the following structure:\n\n```java\nservice.searchTracks(Track.Filter.start()\n              .byName(\"Imagine Dragons\")\n              .byGenres(\"rock\",\"indie\",\"alternative\")\n              .byTags(\"popular\",\"rock\",\"imagine\",\"dragons\")\n              .byLicense(Track.License.ALL_RIGHTS_RESERVED)\n              .byTypes(Track.Type.ORIGINAL, Track.Type.LIVE)\n              .limit(30)\n              .offset(10).createOptions())\n         .subscribeOn(Schedulers.io())\n         .observeOn(AndroidSchedulers.mainThread())\n         .subscribe(tracks-\u003e{\n          //do something     \n       });\n\n```\nThe `Filter` class is a nested class inside of a model class like `User`, `Playlist` or `Track`. Most of them offer a different set of methods because not all models can be filtered in the same way. \nWhenever you need to filter a request, just use the `Filter` class and its available methods. After you've listed all things you need, just call the `Filter.createOptions()` method.\n\n\n## Authentication ##\n\nSoundCloud authentication uses **OAuth 2.0**, a popular open standard used by many popular API providers. \nOAuth 2.0 allows users to authorize your application without disclosing their username and password. \n\nI've created a class called `SoundCloudAuth` which is responsible for the authentication. \nThe main purpose of this class is to obtain an **access token** for your app. \n\nThere are 3 ways you can do this:\n- with user's credentials (username, password)\n- with the authorization code\n- refresh token \n\n**1.** Use the credentials to obtain a token:\n```java\nSoundCloudAuth.create(Config.CLIENT_ID,Config.CLIENT_SECRET_ID)\n\t.addRedirectUri(Config.REDIRECT_URI)\n        .tokenWithCredentials(\"username\",\"password\")\n        .subscribeOn(Schedulers.io())\n        .observeOn(AndroidSchedulers.mainThread())\n        .subscribe(token-\u003e{\n           //use your token \n\t   //launch another activity passing the token\n\t   //or save using the shared preferences\n\t   //eventually you will use the token to do this SoundCloud.appendToken(token)\n        });\n```\n**2**. In order to get an authorization code, you need to open their url in a `WebView`.\nA pop-up window will be opened allowing the user to log in to SoundCloud and approve your app's authorization request.\n\nApproximately it will look like this:\n\n![](https://github.com/vpaliyX/SoundCloud-API/blob/master/art/sound_pop_up.png)\n\nTo make the flow smoother, you can use a `redirect_uri` with a custom protocol scheme and set your app as a handler for that protocol scheme. \nThat's how you should set up your activity in the manifest file:\n```XML\n\u003cactivity android:name=\".MainActivity\"\u003e\n    \u003cintent-filter\u003e\n        \u003caction android:name=\"android.intent.action.VIEW\" /\u003e\n        \u003ccategory android:name=\"android.intent.category.DEFAULT\" /\u003e\n        \u003ccategory android:name=\"android.intent.category.BROWSABLE\" /\u003e\n        \u003cdata android:scheme=\"app_name\" \n            android:host=\"soundcloud\" \n            android:pathPrefix=\"/redirect\"/\u003e\n    \u003c/intent-filter\u003e\n\u003c/activity\u003e\n```\nIn the case above my `redirect_url` looks like this: `app_name://soundcloud/redirect`.\n\nBasically, I did this for you, you just need to handle the response in your activity. \nThat's how the entire process should look like:\n\n```java\nSoundCloudAuth.create(Config.CLIENT_ID,Config.CLIENT_SECRET_ID)\n\t.loginWithActivity(this,Config.REDIRECT_URI,REQUEST_CODE);\n```\nIt launches the login activity(that popup), which returns the authorization code wrapped into Intent.class.\nYou need to handle this in the `onActivityResult()` method. Here's an example:\n\n```java\n@Override\nprotected void onActivityResult(int requestCode, int resultCode, Intent data) {\n\tsuper.onActivityResult(requestCode, resultCode, data);\n        if(requestCode==REQUEST_CODE){\n            if(resultCode==RESULT_OK){\n                String string=data.getDataString();\n                String code= Uri.parse(string).getQueryParameter(\"code\");\n                //get your token\n                SoundCloudAuth.create(Config.CLIENT_ID,Config.CLIENT_SECRET_ID)\n                        .addRedirectUri(Config.REDIRECT_URI)\n                        .tokenWithAuthCode(code)\n                        .subscribeOn(Schedulers.io())\n                        .observeOn(AndroidSchedulers.mainThread())\n                        .subscribe(token-\u003e{\n\n                        });\n            }\n \t}\n}\n```\nOnce you have received your authorization code, request an access token as showed above.\n\n**3**.If you received your token from using user's credentials, you will need to periodically refresh your access token when it expires. In order to achieve that, just call this method:\n\n```java\nSoundCloudAuth.create(Config.CLIENT_ID, Config.CLIENT_SECRET_ID)\n\t.refreshToken(expiredToken)\n        .subscribeOn(Schedulers.io())\n        .observeOn(AndroidSchedulers.mainThread())\n        .subscribe(token-\u003e{\n\t   //use your token here\n        });\n```\n\n## Additional Documentation And Support ##\n- The [SoundCloud API Documentation](https://developers.soundcloud.com/docs/api/reference).\n- The [SoundCloud API Discussion Group](https://groups.google.com/forum/#!forum/soundcloudapi).\n- If you have any questions or you have found some issues, feel free to write in the [Issue Section](https://github.com/vpaliyX/SoundCloud-API/issues).\n\n## Even More Examples  ## \nLet's suppose that you want to fetch playlists and you have an array of different names; you can solve the problem this way:\n\n```java\n //just a dummy Single object\n Single\u003cList\u003cPlaylistEntity\u003e\u003e start = Single.just(new LinkedList\u003c\u003e());\n \tfor(String name:names){\n\t    //combine all of them \n\t    start=Single.zip(start,service.searchPlaylists(PlaylistEntity\n            \t.Filter.start()\n                .byName(name)\n                .createOptions())\n\t\t//if an error occurs, we want to skip it\n                .onErrorResumeNext(Single.just(new ArrayList\u003c\u003e())),(first,second)-\u003e{\n                    if(second!=null){\n                        first.addAll(second);\n                    }\n                    return first;\n                });\n\n  //call all of them\n  start.subscribeOn(Schedulers.io())\n       .observeOn(AndroidSchedulers.mainThread())\n       .subscribe(list-\u003e{\n       \t  //do something\n       });   \n```\n\n\n\n## The End. ##\n\n``````\nMIT License\n\nCopyright (c) 2017 Vasyl Paliy\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n``````\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvpaliy%2Fsoundcloud-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvpaliy%2Fsoundcloud-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvpaliy%2Fsoundcloud-api/lists"}