SlideShare a Scribd company logo
Developer Infrastructure Team: API & Identity
surviv.io fan
J.N Vollmer

Director of Engineering
Responding to Feedback:
What’s New in the Twitch API
TwitchCon 2018 San Jose, California
What’s the New
Twitch API Again?
REST APIs
Webhooks
Identity
TwitchCon 2018 San Jose, California
Top consumers are Extensions and
streamer tools
778%
Growth in usage
Yr-on-Yr
83%
Of the new API traffic
Is Extensions
99.995%
API Uptime
Key Facts About the
New Twitch API in 2018
99.949%
Webhooks Uptime
TwitchCon 2018 San Jose, California
-Consume, create, and update
relevant Twitch-related data
-Build engaging experiences for
Twitch streamers and viewers
-Consistent design across endpoints
-Bulk capabilities where applicable
-Transparent
#1.
/helix REST APIs
WHAT IS THE NEW TWITCH API?
4 Tenets of the New Twitch API
Reliability
Consistency
Simplicity
Transparency
TwitchCon 2018 San Jose, California
- Stream markers
- Game analytics
- Extension Analytics
- Bits leaderboard
- Clips
- User Extensions
Made for
Tools Dev
Games Dev
Extensions Dev
#1.
/helix REST APIs
WHAT’S NEW IN 2018
TwitchCon 2018 San Jose, California
What’s a webhook?
- Stop calling us, we’ll call you
- A Reverse API: a web callback or http push
API
How is this related to standard REST APIs?
- Consistent data schema: identical to
the /helix corresponding APIs
- Built on W3C Websub standard
#2.
Webhooks Benefits
Real-time Events
Cost Savings
No More Polling
WHAT IS THE NEW TWITCH API?
TwitchCon 2018 San Jose, California
new follower?
Your App
Server
Nope
new follower?
Nope
new follower?
Nope
new follower?
You have a new
follower
Twitch
REST Polling
#2 

Webhooks
WHAT’S THE NEW TWITCH API?
TwitchCon 2018 San Jose, California
#2 

Webhooks
WHAT’S THE NEW TWITCH API?
Subscribe to
new followers
Server
Ok
Confirm
subscription?
Ok
new follower
Webhook Flows
new follower
new follower
Twitch
TwitchCon 2018 San Jose, California
- Stream Changed (initially stream
Up/Down)
- User Changed
- Game Analytics
- Extension Analytics
- Webhooks Subscription
Management API
WHAT’S NEW IN 2018?
#2.
Webhooks
TwitchCon 2018 San Jose, California
- Who can access what resources,
with what permissions
- In the API context, our solution for
authenticating and authorizing API
calls
- OAuth 2 Standard
#3.
Identity
WHAT IS THE NEW TWITCH API?
TwitchCon 2018 San Jose, California
- Many behind-the-scenes security
and performance improvements
- Revamped app authorization screen
Benefits:
- Security
- Performance
- Security!
#3.
Identity
WHAT’S NEW IN 2018?
TwitchCon 2018 San Jose, California
- Quick and frictionless onboarding:
build a new test integration from
scratch in minutes
- Limits on what each integration can
do by default
• For the greater good of the
developer community
• To protect users’ private data
- Protection and support to enable
high-traffic integrations
Overall
WHAT’S THE NEW TWITCH API?
TwitchCon 2018 San Jose, California
What Do You
(Twitch API Developers)
Want?
Your feedback and what we’re
doing about it
TwitchCon 2018 San Jose, California
“We’ve had three big ideas […]
that we’ve stuck with for 18 years,
and they’re the reason we’re
successful: Put the customer first.
Invent. And be patient.”
TwitchCon 2018 San Jose, California
“We’ve had three big ideas […]
that we’ve stuck with for 18
years, and they’re the reason
we’re successful: Put the
customer first. Invent. And be
patient.”
TwitchCon 2018 San Jose, California
Collect Feedback
Identify
Challenges
Trade Offs &
Solutions
Design
Philosophy
Steering
Committee
How Twitch API

Puts the
Customer First
TwitchCon 2018 San Jose, California
You want to get relevant data in as few
calls as possible.
- userID field in API responses is generally
“not useful enough”
- API is too chatty
- Worse for webhooks: a push should not
need subsequent pulls
- “90% of our calls to the new Twitch API
are to translate userIDs to userNames.”
Data
Fragmentation
PROBLEM #1
TwitchCon 2018 San Jose, California
Instead of just returning the userID to
represent a user in API responses and
webhooks, we are adding the
userName
A more pragmatic and flexible approach
Denormalization
of Key Field
SOLUTION #1
BEFORE: A USER == { USERID }
AFTER: A USER == { USERID, USERNAME }
Lower the number of calls
TwitchCon 2018 San Jose, California
Restrictive
Rate Limiting
PROBLEM #2
- Existing rate limiting mechanism is
client-ID based
- Good intention: protect everyone and
enable scaling
BUT:
- Prevents your app from being popular
- Large spike in viewership will bring the
number of calls over the limit and make
an app unusable
- Compounded by problem #1 (need for
additional API requests)
TwitchCon 2018 San Jose, California
Token bucket algorithm: burst
friendly by design
Variable point value per endpoint
Supports continous growth and burst
Smart Rate
Limiting
SOLUTION #2
Your limit varies with user generated traffic
Based on:
- clientID+userID for calls that provide an
OAuth token
- IP for calls otherwise
TwitchCon 2018 San Jose, California
Subscriptions API
Endpoint
PROBLEM #1
- Exists in the legacy v5 API
BUT:
- Unreliable; some fields are inconsistent
- Suboptimal design; legacy API is too
permissive
TwitchCon 2018 San Jose, California
New Subscriptions
API Endpoint
SOLUTION #3
Enables two use cases:
- Get list of subscribers for a channel
- Confirm whether a viewer is
subscribed to a given channel
BONUS:
-Webhook
BENEFITS
- Safer
- Consistent
- Real-time data push
TwitchCon 2018 San Jose, California
What Can You
Build?
A few ideas…
TwitchCon 2018 San Jose, California
Use Case:
Stream Markers
ELGATO STREAM DECK
Announcement: https://discuss.dev.twitch.tv/t/introducing-the-stream-markers-api/
- Programmable keypad with 15 LCD
- Specifically built for streamers; very
popular
- First product of its kind that replaces
random keybindings
Stream Markers API enables a
“marker button”
TwitchCon 2018 San Jose, California
Use Case:
Stream Markers
TwitchCon 2018 San Jose, California
“The Create Stream Marker API is
perfect for our use case.
I quickly implemented it in Stream Deck
and this works great: […] the Stream
Marker automagically appears in Twitch.
- Alexandre Colucci, Tech Lead @elgato
TwitchCon 2018 San Jose, California
“New Follower”
Webhook
STREAMLABS WIDGETS
- Push real-time on screen
notifications to viewers when a
streamer gets a new follower
- Leads to streamer and viewer
excitement and engagement with
viewers
- Before webhooks, the use case could
only be accomplished with polling,
with delays
TwitchCon 2018 San Jose, California
STREAMLABS
“New follower”
webhook
TwitchCon 2018 San Jose, California
How Do I
Get Started?
A quick tutorial/refresher…
TwitchCon 2018 San Jose, California
Sign into Twitch
Dev Site
GETTING STARTED
HTTP://DEV.TWITCH.TV
TwitchCon 2018 San Jose, California
Create an Extension
or App
GETTING STARTED
- Apps are a simple basic
construct to make API calls
- Extensions are more
sophisticated, but based on the
same core concepts. Use the
Extensions Dev Rig on Github!
- You will receive a client ID and a
client Secret
- Pass the Client-ID in a header
- Get the data
Pros:
- Simple
Cons:
- Low rate limit
Call an
‘Anonymous’
Endpoint
BASIC USE CASE
TwitchCon 2018 San Jose, California
Create and Use a
Bearer Token
REGULAR USE CASE
- Three types of tokens
- Three types of flows
https://dev.twitch.tv/docs/
authentication/#getting-tokens
- Simplest combination: OAuth user
access token with implicit grant
- Request only the scopes you need
TwitchCon 2018 San Jose, California
OAuth 2 Implicit
Grant Flow
Your App
(Client)
Twitch Server
Authorization
Endpoint
(id.twitch.tv)
#1
Authentication/
Authorization
Request
Twitch User
#2
Auth Request
Twitch Server
Authorization
Endpoint
(id.twitch.tv)
#3
Auth Granted
Your App
(Client)
#4
Access Token
OAuth user access token with
implicit grant Simple
How to Create a
Bearer Token
curl -X GET 'https://id.twitch.tv/oauth2/authorize?
response_type=token&client_id=uo6dggojyb8d6soh92zknwmi
ej1q2&redirect_uri=http://
localhost&scope=viewing_activity_read&state=c3ab8aa609
a11e793ae92361f002671'
//Redirects to”:
https://
localhost#access_token=0123456789abcdefghijABCDEFGHIJ
&scope=viewing_activity_read
&state=c3ab8aa609ea11e793ae92361f002671
&token_type=bearer
1

2

3

4

5

6

7

8

9

1
0

1
1

How to Create a Bearer Token
Calling the Users API to Retrieve Details of a Given User
curl -H 'Authorization: Bearer cfabdegwdoklmawdzdo98xt2fo512y' 
-X GET 'https://api.twitch.tv/helix/users?id=44322889'
{
"data": [{
"id": "44322889",
"login": "dallas",
"display_name": "dallas",
"type": "staff",
"broadcaster_type": "",
"description": "Just a gamer playing games and chatting. :)",
"profile_image_url": "https://static-cdn.jtvnw.net/jtv_user_pictures/d.png",
"offline_image_url": "https://static-cdn.jtvnw.net/jtv_user_pictures/d.png",
"view_count": 191836881,
"email": "login@provider.com"
}]
}
1

2

3

4

5

6

7

8

9

10

11

12
13
14
15
16
17
18
That’s it!
You are ready to roll
Questions?
See you on https://dev.twitch.tv
Thank you!

More Related Content

Responding to Feedback: What's New in the Twitch API

  • 1. Developer Infrastructure Team: API & Identity surviv.io fan J.N Vollmer
 Director of Engineering
  • 2. Responding to Feedback: What’s New in the Twitch API
  • 3. TwitchCon 2018 San Jose, California What’s the New Twitch API Again? REST APIs Webhooks Identity
  • 4. TwitchCon 2018 San Jose, California Top consumers are Extensions and streamer tools 778% Growth in usage Yr-on-Yr 83% Of the new API traffic Is Extensions 99.995% API Uptime Key Facts About the New Twitch API in 2018 99.949% Webhooks Uptime
  • 5. TwitchCon 2018 San Jose, California -Consume, create, and update relevant Twitch-related data -Build engaging experiences for Twitch streamers and viewers -Consistent design across endpoints -Bulk capabilities where applicable -Transparent #1. /helix REST APIs WHAT IS THE NEW TWITCH API? 4 Tenets of the New Twitch API Reliability Consistency Simplicity Transparency
  • 6. TwitchCon 2018 San Jose, California - Stream markers - Game analytics - Extension Analytics - Bits leaderboard - Clips - User Extensions Made for Tools Dev Games Dev Extensions Dev #1. /helix REST APIs WHAT’S NEW IN 2018
  • 7. TwitchCon 2018 San Jose, California What’s a webhook? - Stop calling us, we’ll call you - A Reverse API: a web callback or http push API How is this related to standard REST APIs? - Consistent data schema: identical to the /helix corresponding APIs - Built on W3C Websub standard #2. Webhooks Benefits Real-time Events Cost Savings No More Polling WHAT IS THE NEW TWITCH API?
  • 8. TwitchCon 2018 San Jose, California new follower? Your App Server Nope new follower? Nope new follower? Nope new follower? You have a new follower Twitch REST Polling #2 
 Webhooks WHAT’S THE NEW TWITCH API?
  • 9. TwitchCon 2018 San Jose, California #2 
 Webhooks WHAT’S THE NEW TWITCH API? Subscribe to new followers Server Ok Confirm subscription? Ok new follower Webhook Flows new follower new follower Twitch
  • 10. TwitchCon 2018 San Jose, California - Stream Changed (initially stream Up/Down) - User Changed - Game Analytics - Extension Analytics - Webhooks Subscription Management API WHAT’S NEW IN 2018? #2. Webhooks
  • 11. TwitchCon 2018 San Jose, California - Who can access what resources, with what permissions - In the API context, our solution for authenticating and authorizing API calls - OAuth 2 Standard #3. Identity WHAT IS THE NEW TWITCH API?
  • 12. TwitchCon 2018 San Jose, California - Many behind-the-scenes security and performance improvements - Revamped app authorization screen Benefits: - Security - Performance - Security! #3. Identity WHAT’S NEW IN 2018?
  • 13. TwitchCon 2018 San Jose, California - Quick and frictionless onboarding: build a new test integration from scratch in minutes - Limits on what each integration can do by default • For the greater good of the developer community • To protect users’ private data - Protection and support to enable high-traffic integrations Overall WHAT’S THE NEW TWITCH API?
  • 14. TwitchCon 2018 San Jose, California What Do You (Twitch API Developers) Want? Your feedback and what we’re doing about it
  • 15. TwitchCon 2018 San Jose, California “We’ve had three big ideas […] that we’ve stuck with for 18 years, and they’re the reason we’re successful: Put the customer first. Invent. And be patient.”
  • 16. TwitchCon 2018 San Jose, California “We’ve had three big ideas […] that we’ve stuck with for 18 years, and they’re the reason we’re successful: Put the customer first. Invent. And be patient.”
  • 17. TwitchCon 2018 San Jose, California Collect Feedback Identify Challenges Trade Offs & Solutions Design Philosophy Steering Committee How Twitch API
 Puts the Customer First
  • 18. TwitchCon 2018 San Jose, California You want to get relevant data in as few calls as possible. - userID field in API responses is generally “not useful enough” - API is too chatty - Worse for webhooks: a push should not need subsequent pulls - “90% of our calls to the new Twitch API are to translate userIDs to userNames.” Data Fragmentation PROBLEM #1
  • 19. TwitchCon 2018 San Jose, California Instead of just returning the userID to represent a user in API responses and webhooks, we are adding the userName A more pragmatic and flexible approach Denormalization of Key Field SOLUTION #1 BEFORE: A USER == { USERID } AFTER: A USER == { USERID, USERNAME } Lower the number of calls
  • 20. TwitchCon 2018 San Jose, California Restrictive Rate Limiting PROBLEM #2 - Existing rate limiting mechanism is client-ID based - Good intention: protect everyone and enable scaling BUT: - Prevents your app from being popular - Large spike in viewership will bring the number of calls over the limit and make an app unusable - Compounded by problem #1 (need for additional API requests)
  • 21. TwitchCon 2018 San Jose, California Token bucket algorithm: burst friendly by design Variable point value per endpoint Supports continous growth and burst Smart Rate Limiting SOLUTION #2 Your limit varies with user generated traffic Based on: - clientID+userID for calls that provide an OAuth token - IP for calls otherwise
  • 22. TwitchCon 2018 San Jose, California Subscriptions API Endpoint PROBLEM #1 - Exists in the legacy v5 API BUT: - Unreliable; some fields are inconsistent - Suboptimal design; legacy API is too permissive
  • 23. TwitchCon 2018 San Jose, California New Subscriptions API Endpoint SOLUTION #3 Enables two use cases: - Get list of subscribers for a channel - Confirm whether a viewer is subscribed to a given channel BONUS: -Webhook BENEFITS - Safer - Consistent - Real-time data push
  • 24. TwitchCon 2018 San Jose, California What Can You Build? A few ideas…
  • 25. TwitchCon 2018 San Jose, California Use Case: Stream Markers ELGATO STREAM DECK Announcement: https://discuss.dev.twitch.tv/t/introducing-the-stream-markers-api/ - Programmable keypad with 15 LCD - Specifically built for streamers; very popular - First product of its kind that replaces random keybindings Stream Markers API enables a “marker button”
  • 26. TwitchCon 2018 San Jose, California Use Case: Stream Markers
  • 27. TwitchCon 2018 San Jose, California “The Create Stream Marker API is perfect for our use case. I quickly implemented it in Stream Deck and this works great: […] the Stream Marker automagically appears in Twitch. - Alexandre Colucci, Tech Lead @elgato
  • 28. TwitchCon 2018 San Jose, California “New Follower” Webhook STREAMLABS WIDGETS - Push real-time on screen notifications to viewers when a streamer gets a new follower - Leads to streamer and viewer excitement and engagement with viewers - Before webhooks, the use case could only be accomplished with polling, with delays
  • 29. TwitchCon 2018 San Jose, California STREAMLABS “New follower” webhook
  • 30. TwitchCon 2018 San Jose, California How Do I Get Started? A quick tutorial/refresher…
  • 31. TwitchCon 2018 San Jose, California Sign into Twitch Dev Site GETTING STARTED HTTP://DEV.TWITCH.TV
  • 32. TwitchCon 2018 San Jose, California Create an Extension or App GETTING STARTED - Apps are a simple basic construct to make API calls - Extensions are more sophisticated, but based on the same core concepts. Use the Extensions Dev Rig on Github! - You will receive a client ID and a client Secret
  • 33. - Pass the Client-ID in a header - Get the data Pros: - Simple Cons: - Low rate limit Call an ‘Anonymous’ Endpoint BASIC USE CASE
  • 34. TwitchCon 2018 San Jose, California Create and Use a Bearer Token REGULAR USE CASE - Three types of tokens - Three types of flows https://dev.twitch.tv/docs/ authentication/#getting-tokens - Simplest combination: OAuth user access token with implicit grant - Request only the scopes you need
  • 35. TwitchCon 2018 San Jose, California OAuth 2 Implicit Grant Flow Your App (Client) Twitch Server Authorization Endpoint (id.twitch.tv) #1 Authentication/ Authorization Request Twitch User #2 Auth Request Twitch Server Authorization Endpoint (id.twitch.tv) #3 Auth Granted Your App (Client) #4 Access Token
  • 36. OAuth user access token with implicit grant Simple How to Create a Bearer Token curl -X GET 'https://id.twitch.tv/oauth2/authorize? response_type=token&client_id=uo6dggojyb8d6soh92zknwmi ej1q2&redirect_uri=http:// localhost&scope=viewing_activity_read&state=c3ab8aa609 a11e793ae92361f002671' //Redirects to”: https:// localhost#access_token=0123456789abcdefghijABCDEFGHIJ &scope=viewing_activity_read &state=c3ab8aa609ea11e793ae92361f002671 &token_type=bearer 1
 2
 3
 4
 5
 6
 7
 8
 9
 1 0
 1 1

  • 37. How to Create a Bearer Token Calling the Users API to Retrieve Details of a Given User curl -H 'Authorization: Bearer cfabdegwdoklmawdzdo98xt2fo512y' -X GET 'https://api.twitch.tv/helix/users?id=44322889' { "data": [{ "id": "44322889", "login": "dallas", "display_name": "dallas", "type": "staff", "broadcaster_type": "", "description": "Just a gamer playing games and chatting. :)", "profile_image_url": "https://static-cdn.jtvnw.net/jtv_user_pictures/d.png", "offline_image_url": "https://static-cdn.jtvnw.net/jtv_user_pictures/d.png", "view_count": 191836881, "email": "login@provider.com" }] } 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12 13 14 15 16 17 18
  • 38. That’s it! You are ready to roll
  • 40. See you on https://dev.twitch.tv Thank you!