GithubHelp home page GithubHelp logo

michidk / twitchcsharp Goto Github PK

View Code? Open in Web Editor NEW
43.0 7.0 12.0 524 KB

Twitch C# Wrapper for the Twitch v3 REST API

License: Apache License 2.0

C# 100.00%
oauth-keys wrapper c-sharp twitch rest api oauth

twitchcsharp's Introduction

Twitch C# Wrapper for the Twitch v3 REST API

Notes

If you are using Twitch C# Wrapper for your project, please let me know! If there are many projects using this API, I will update it more frequently. If you are interested in a Twitch C# API Wrapper with active support or Unity 5 integration for the new Twitch v5 API and are willing to pay for it, please contact me.

For news & updates, follow me on Twitter: @miichidk

Projects Using Twitch C# Wrapper

Documentation

This project is just a wrapper, so that you can interact with the Twitch REST API using C#. That means that most of the methods are named and work like requests of the Twitch REST API. The Twitch REST API is documented here.

Usage

Client

To interact with the API you need at least a client-ID. Some requests can only be made by authorized users. These also need a OAuth-key.

There are three client classes:

Class Explanation
TwitchReadOnlyClient you can use this client without an auth-key to access public data
TwitchAuthenticatedClient needs to authenticate via auth-key, can access and change private data

The TwitchReadOnlyClient can be used to read basic informations which are public on Twitch like the follower count of certain people. Requests which access data which is not public or do change something (e.g. the stream title) need authentication. For these requests you should use the TwitchAuthenticatedClient. The authenticated client also has access to all TwitchReadOnlyClient methods. The TwitchNamedClient is deprecated, since the TwitchAuthenticatedClient automatically fetches the username.

OAuth-Key / Client-ID

Your client-ID is used to protect the twitch servers from spam-attacks. You can create one here (scroll to the bottom).

You auth-key is used to authenticate you with the twitch servers. To generate one, just put your client-ID after "client_id=" in the URL and visit the following link:

https://api.twitch.tv/kraken/oauth2/authorize?response_type=token&client_id=INSERT_YOUR_CLIENT_ID_HERE&redirect_uri=http://localhost&scope=user_read+user_blocks_edit+user_blocks_read+user_follows_edit+channel_read+c
hannel_editor+channel_commercial+channel_stream+channel_subscriptions+user_subscriptions+channel_check_subscription+chat_login

You will be redirected to a url like this:

http://localhost/#access_token=qxxxxtnc33456quxfghmcpw211s92xgp&scope=user_read+user_blocks_edit+user_blocks_read+user_follows_edit+channel_read+channel_editor+channel_commercial+channel_stream+channel_subscriptions+user_subscriptions+channel_check_subscription+chat_login

You can find your auth-key in the resulting url: #access_token=qxxxxtnc33456quxfghmcpw211s92xgp If you create a service, you have to provide a web-frontend, for the users to get their auth-key. Auth-keys are bound to accounts and should not be shared.

Read more about the Twitch authentication API here.

Example

// create a new client with access to the account to the auth-key owner
var client = new TwitchAuthenticatedClient("client-id", "oauth-key");

client.Follow("miichidk");					// the owner of the auth-key will follow the user 'michidk'

foreach (var follower in client.GetFollowers("michidk").List)
{
    Console.WriteLine(follower.User.Name);	// print out all followers of the user 'michidk'
}

Dependencies

License

Used some code from Gibletto.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Misc

Created 2015 by Michael Lohr

Analytics

twitchcsharp's People

Contributors

dependabot[bot] avatar erictuvesson avatar jerotire avatar michidk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

twitchcsharp's Issues

How to implement?

Hi,

I am new to C#. I couldn't find this on Nuget - how do i add it to my project?

Cheers

TopGames returning NULL

Is anyone else having issues calling "Top Games"? Yesterday I was getting data back all the time while in development but today when I went back to testing, I get null every time. I wonder if Twitch banned my IP? Is there anyway to get error codes? I'm using the read only client so no access needed.

Now you need Client-ID for all requests

Since august you now have to provide the Client-ID in the header for each request.
So ReadOnly client doesn't work anymore...

(I just got a troubleshoot when using GetStream from AuthenticatedClient... but it's the ReadOnly method which is called because of parenting. And this result in a 400 error / no client-id provided.)

TwitchAuthenticatedClient - couldn't get user name!

When I create a new object of TwitchAuthenticatedClient it throws a new exepction:

An exception of type 'TwitchCSharp.Helpers.TwitchException' occurred in TwitchCSharp.dll but was not handled in user code
Additional information: Couldn't get the user name!

In this line:
TwitchAuthenticatedClient client = new TwitchAuthenticatedClient(clientId, authKey);
clientId - i have from https://www.twitch.tv/settings/connections in my app
authKey - from redirected link
looks like this
var authKey = "1mba3xxxxxxxxxxxxxxxxxxxxxxxxx";
var clientId = "9b4gw0xxxxxxxxxxxxxxxxxxxxxxxxx";

Whats wrong?

TwitchCSharp for VS2008

Hi!
I've tried to compile your wrapper for net35 to use it in VS2008 but either im missing something or your code simply isnt compatible for net35 .. i cant tell exactly as i've never really used VS2012 or net45
Before you ask, yes i set the nuget config to use net35 version of the required libs and set the project to net35 too, but i still get linker warnings naming something about net45 and net35 ..

Maybe you could add a release for .net 3.5?

Thanks in advance

GetEmoticons() wrong MIME response

public TwitchList<Emoticon> GetEmoticons()
{
    var request = GetRequest("chat/emoticons", Method.GET);
    var response = restClient.Execute<TwitchList<Emoticon>>(request);
    return response.Data;
}

The response's ContentType is "text/html" which causes the data to not be parsed, a simple fix to this would be to change the request uri to "chat/emoticon_images".

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.