Giter Club home page Giter Club logo

soundcloud.api.client's Introduction

##SoundCloud.API.Client

Build status

About

.NET API implementation https://developers.soundcloud.com/docs/api/reference

Warning

If you run tests frequently from one account, soundcloud may ban it.

#Install Build and use SoundCloud.API.Client.dll or inject via nuget: https://www.nuget.org/packages/SoundCloud.API.Client

HowTo

Direct connection via username and password. Good for debugging and tests.

ISoundCloudConnector soundCloudConnector = new SoundCloudConnector();
soundCloudClient = soundCloudConnector.DirectConnect("clientId", "clientSecret", "username", "password");
var user = soundCloudClient.User("42").GetUser();
Console.WriteLine(user.Id); //42

OAuth connection.

First of all go to your app page and fill 'Redirect URI for Authentication' field with your redirect_uri.

In my example I used this value: http://localhost:50086/Home/GetCode

You can find this sample here: .\SoundCloud.API.Client\SoundCloud.API.Client.Web\Controllers\HomeController.cs

public class HomeController : Controller
{
	private readonly ISoundCloudConnector soundCloudConnector = new SoundCloudConnector();

	//put your app credentials here
	private const string clientId = "";
	private const string clientSecret = "";

	//specify redirect_uri
	private const string redirectUri = "http://localhost:50086/Home/GetCode";

	public ActionResult Index()
	{
		return View();
	}

	public ActionResult RequestCode()
	{
		var requestTokenUri = soundCloudConnector.GetRequestTokenUri(clientId, redirectUri, SCResponseType.Code, SCScope.NonExpiring, SCDisplay.Popup, null);
		return Redirect(requestTokenUri.ToString());
	}

	public ActionResult GetCode(string error, [Bind(Prefix = "error_description")] string errorDescription, string code)
	{
		if (!string.IsNullOrEmpty(error))
		{
			return Content(string.Format("Error: {0}", errorDescription));
		}

		//connect with code
		var soundCloudClient = soundCloudConnector.Connect(clientId, clientSecret, code, redirectUri);
		
		var accessToken = soundCloudClient.CurrentToken;
		
		//you also can connect next time with token
		soundCloudClient = soundCloudConnector.Connect(accessToken);

		var user = soundCloudClient.Me.GetUser();

		return Content(string.Format("Your full name is {0}. Current token: {1}", user.FullName, accessToken.AccessToken));
	}
}

If your token expires you can use soundCloudConnector.RefreshToken.

#Interface All methods reside in SoundCloudClient:

public interface ISoundCloudClient
{
	SCAccessToken CurrentToken { get; }

	IUserApi User(string userId);
	IUsersApi Users { get; }
	
	ITrackApi Track(string trackId);
	ITracksApi Tracks { get; }

	IPlaylistApi Playlist(string playlistId);

	IGroupApi Group(string groupId);
	IGroupsApi Groups { get; }

	IMeApi Me { get; }

	ICommentApi Comment(string commentId);

	IAppApi App(string appId);

	IResolveApi Resolve { get; }

	IOEmbed OEmbed { get; }
}

Let's have a look at IGroupApi, for example. You must specify context by Id.

public interface IGroupApi
{
	SCGroup GetGroup();
	
	SCUser[] GetModerators(int offset = 0, int limit = 50);
	SCUser[] GetMembers(int offset = 0, int limit = 50);
	SCUser[] GetContributors(int offset = 0, int limit = 50);
	SCUser[] GetUsers(int offset = 0, int limit = 50);
	
	SCTrack[] GetApprovedTracks(int offset = 0, int limit = 50);
	SCTrack[] GetPendingTracks(int offset = 0, int limit = 50);
	SCTrack GetPendingTrack(string trackId);
	void AcceptPendingTrack(string trackId);
	void RejectPendingTrack(string trackId);

	SCTrack[] GetContributions(int offset = 0, int limit = 50);
	SCTrack GetContribution(string trackId);
	void CreateContribution(string trackId);
	void DeleteContribution(string trackId);
}

Simple usage:

var soundCloudClient = soundCloudConnector.Connect(accessToken);
var moderators = soundCloudClient.Group("42").GetModerators();

Also you can find some useful things like a fluent query executor:

var embed = soundCloudClient.OEmbed
							.BeginQuery(url)
							.SetAutoPlay(true)
							.SetCallback("dropTable()")
							.SetColor("c6c6c6")
							.SetIFrame(false)
							.SetMaxHeight(95)
							.SetMaxWidth(42)
							.SetShowComments(false)
							.ExecuteJson();

#Tests If you want to run tests, you should fill settings.json first.

Full path: .\SoundCloud.API.Client\SoundCloud.API.Client.Test\settings.json

{
	"ClientId" : "",
	"ClientSecret" : "",
	"UserName" : "",
	"Password" : "",
	"TestAppId" : ""
}

You can also specify optional fields here: TestGroupId, TestTrackId, TestUserId

#What's next It's almost stable right now. You can check out tests with your credentials.

Furthermore I want to implement api console into web-project like it's done here: https://developers.soundcloud.com/console

But better. :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.