{"id":13530710,"url":"https://github.com/GameMakerDiscord/GMTwitch","last_synced_at":"2025-04-01T19:30:34.018Z","repository":{"id":36159620,"uuid":"40463692","full_name":"GameMakerDiscord/GMTwitch","owner":"GameMakerDiscord","description":"Lightweight, open source Twitch interface for Game Maker: Studio","archived":false,"fork":false,"pushed_at":"2022-01-03T22:53:34.000Z","size":159,"stargazers_count":68,"open_issues_count":7,"forks_count":20,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-11-02T17:36:28.604Z","etag":null,"topics":["example","gms1","library"],"latest_commit_sha":null,"homepage":null,"language":"Game Maker Language","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/GameMakerDiscord.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-10T04:50:38.000Z","updated_at":"2024-10-20T23:09:38.000Z","dependencies_parsed_at":"2022-08-18T00:15:12.765Z","dependency_job_id":null,"html_url":"https://github.com/GameMakerDiscord/GMTwitch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GameMakerDiscord%2FGMTwitch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GameMakerDiscord%2FGMTwitch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GameMakerDiscord%2FGMTwitch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GameMakerDiscord%2FGMTwitch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GameMakerDiscord","download_url":"https://codeload.github.com/GameMakerDiscord/GMTwitch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246700018,"owners_count":20819812,"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":["example","gms1","library"],"created_at":"2024-08-01T07:00:53.871Z","updated_at":"2025-04-01T19:30:33.574Z","avatar_url":"https://github.com/GameMakerDiscord.png","language":"Game Maker Language","readme":"\u003ci\u003eMaintained by: kbjwes77\u003c/i\u003e\n\n# GMTwitch\n\n\u003cb\u003e\u003cspan style=\"color:#00DD00;\"\u003eMAJOR UPDATE:\u003c/span\u003e\u003c/b\u003e Each HTTP request to Twitch now requires a Client ID inside the header. Going forward, you will have to supply a Twitch Client ID as an argument with the initialization script: ```twitch_init(clientID);```. See the section on **Initialization** below for instructions for getting a Twitch Client ID for your application.\n\n\u003cb\u003e\u003cspan style=\"color:#00DD00;\"\u003ePrevious Updates:\u003c/span\u003e\u003c/b\u003e Added the ability to chat using four new functions described at the bottom of this doc!\n\n___\n\n\u003e What is GMTwitch?\n\nGMTwitch is a lightweight, open source Twitch API wrapper/interface for Game Maker: Studio\n\n\u003e You say lightweight, how complicated is it?\n\nThis interface uses only **fifteen** scripts, all vanilla code withouth any extensions or included files.\n\n\u003e How do I use these scripts?\n\nGetting stream details is easy as pie as soon as you understand the workflow. It's simply:\n\n**Initialization -\u003e Request Info -\u003e Receive Info -\u003e Utilize Info**\n\nWith the new version, you can even send and receive chat messages to any live stream!\n\nBelow, I'm going to initially go into detail on the process of how to get the details of any live stream using\nGMTwitch in your own project. I'll even give you a quick code example. Then I'll quickly go over the chat functions.\n\nReady? **Let's go!**\n\n___\n\n**Initialization**\n\n```\ntwitch_init( clientID );\n```\n\n\nThe first step is really only one line of code, usually in the create event of a controller object.\nNo extensions to setup, no libraries or DLL's. Just one script.\n\nThe only value you need to pass into the script to get up and running is a Twitch Client ID. The other scripts will automatically put it into the headers of each request for you! [You can create a Client ID here](https://www.twitch.tv/kraken/oauth2/clients/new). Set the redirect to localhost as recommended, then copy the ID from the URL in your browser.\n\n*credit goes to the developer [chalenged](https://github.com/chalenged) for creating a pull request to update this API to work with Twitch's new request system*\n\n___\n\n**Request Info**\n\n```\ntwitch_stream_get_info( channel_id );\ntwitch_stream_get_thumbnail( channel_id, size );\n```\n\n\nNext we move on to the part where we ask Twitch for stream details. This only involves two scripts.\nYou can drop these scripts anywhere in your code, just note that putting them in the step event is not only\nwasteful, but it will probably crash the game/cause unexpected errors. You only need to call each script once\nfor it to request the info. Of course you can put them on a timer or use the auto update script I'll cover later.\n\n\u003e You'll notice both of these scripts require a single, shared parameter: *channel_id*\n\u003e This is simply the unique channel identification handle for the live stream to be hosted on. So, for example, say\n\u003e you are trying to find the details for a livestream being broadcasted at the URL: http://twitch.tv/xarrotstudios/\n\u003e To find the channel id, just take the string after the \"twitch.tv/\" part, not including the backslash following it\n\u003e For our example, the channel id would be *xarrotstudios*. Make sure it's represented as a string, and you're all set.\n\nThe first script makes an HTTP GET request to the exposed Twitch API, asking for the full details (JSON formatted)\nfor the channel id provided. This also sets up the data structure to store the payload we are waiting for.\n\nThe second script is a little trickier, but not much at all. The only requirement to use the second script is that\nthe first script ```twitch_stream_get_info();``` must have been called *and* the corresponding data received. You will\nnot get an error calling it before, it just doesn't do anything useful if the preceding script wasn't called.\nOnce you have got your info for the stream, and then you request the thumbnail properly, all it does is make a\nnew, separate request for a thumbnail in a specified size. You can fiddle with the sizes in that script, it's all\nup to the user on what size thumbnail the server will respond with. That's it for the requests\n\n___\n\n**Receive Info**\n\n```\ntwitch_async();\n```\n\n\nThis one is the easiest. Drop it into the HTTP Async event. Done. Finished. Complete. Moving on!\n\n___\n\n**Utilize Info**\n\n```\ntwitch_stream_find_value( channel_id, key );\n```\n\nArguably the hardest step of the whole process, only because we have a bunch of keys to throw at you, and they return\nall sorts of different things. You'll find that it's actually a breeze to use once you take a look at the keys.\nIt's all packed into one tight script, so I thought this was the best way to keep the whole\nmotif of 'simple scripts, simple parameters' going smoothly. Here is an example of the mentioned script:\n\n```\nvar info = twitch_stream_find_value( channel_id, key );\n```\n\nAgain, you have your *channel_id* handle, but now we are using a key to indentify the data we want to retrieve. Also,\nthis is the first script we've covered that has a return value. Let's see if I can cover this stuff in an neat way.\nThe return value is the data you want that has already been picked up by the \u003ccode\u003etwitch_async()\u003c/code\u003e script. It was already\nstored (if you did everything right, come on there's no way to screw this up) and now we are just using this\nnewly acquired tool to seamlessly extract the information. If the info has not made it to us yet, (for example\nwe forgot to request the info in the first place or there's heavy traffic and we experience a delay) the return value\nwill be a constant Game Maker recognizes as *undefined*. So, typically you would make sure to do a quick check before\nyou compare anything, by making sure it's not an undefined value. If we didn't have any delays and we remembered to\nwrite our code to request the info in the first place, we did great! All of the stream's details are ready for us to\naccess. But how do we access those details? Keys! The following table will kindly explain what each key does and\nwhat you should expect to be returned using each key:\n\n| Key           | Returns       | Return Type  |\n|:-------------:|:-------------:|:-----:|\n| \"status\"      | online/offline | True/False |\n| \"name\"        | stream's channel name | String |\n| \"game\" | game the stream is broadcasting | String |\n| \"url\"        | URL to watch stream | String |\n| \"viewers\" | current viewer count | String |\n| \"views\" | total viewer count | String |\n| \"followers\" | total follower count | String |\n| \"thumb_url\" | URL template for preview thumbnail | String |\n| \"thumb\" | sprite handle of thumbnail | Real |\n\n___\n\n**Stream Details Example Code**\n\nIt's super easy to use, almost everything is done behind the scenes for you. Here's a small example, we will see if a stream is online and broadcasting. All we will do is initiallize, request, recieve, then utilize. Check it out:\n\n```\n// Create Event\ntwitch_init(clientID);\ntwitch_stream_get_info(\"xarrotstudios\");\n\n// HTTP Async Event\ntwitch_async();\n\n// Draw Event\nif (twitch_stream_find_value(\"xarrotstudios\",\"status\"))\n    draw_text(12,12,\"Xarrot Studios is ONLINE!\");\nelse\n    draw_text(12,12,\"Xarrot Studios is OFFLINE!\");\n```\n\nJust **seven**, easily digestable lines of code, and you can almost immediately show if the channel is live. No dealing with crazy, messy webs of handles, bloated code or extensions. It's just the bare minimum and I think you'll agree it's all you'll ever need.\n\n___\n\n**Twitch Chat Functions**\n\n*credit goes to [u/Aidan63](https://www.reddit.com/user/Aidan63) for providing a foundation to these new scripts*\n\nYou can now send and receive chat messages from any Twitch stream using the four new functions added in the latest update:\n\n```\n// connects to a Twitch IRC chat channel\ntwitch_chat_connect( channel_id, username, oauth);\n\n// receives data in the Networking Async event\ntwitch_chat_async();\n\n// allows you to send a string as a chat message\ntwitch_chat_say( string );\n\n// disconnects from a connected chat channel\ntwitch_chat_disconnect();\n```\n\nUsing these functions are covered in the source of the example, and they are very self explanitory, so I won't go\nthrough any examples or get into details with these. All chat messages are stored in a single list, even the chat\nmessages you send yourself. That's pretty much the gist of it. What I will go on to say is that to connect\nto a Twitch IRC channel, you must have *two previously created resources* that can't be created\nthrough the scope of my scripts. The first is a **valid Twitch user account**. That's the simple part.\nThe second half, involves getting an **Oauth token** for the Twitch user account you will be connecting\nto the chat with. You can get a working Oauth token here: http://www.twitchapps.com/tmi/\n\nOne thing to note: sending more than [20 messages to a stranger's chat] or [100 messages to your own stream's chat]\nwill **ban you for 8 hours from all Twitch IRC activity**. So be careful when testing these new chat scripts. *There is\nno getting around the ban*, and you will have to wait eight more hours to test again. Test wisely!\n\nYou just saw the entirety of the new chat functions! Easy and simple!\n\n___\n\n**Wrapping Up The Wrapper**\n\nThat's it! Those are the core functions used to wrap up the API nice and neat for you guys. Use it, abuse it, fork it,\nspoon it. I don't care. No credit required. Just don't claim this as your own! Now, before you leave, I'll\nlist the last of the scripts and give a brief description of each:\n\n```\n// Place in the step event to auto update all active channel info on a timer\ntwitch_auto_update();\n\n// Place anywhere to manually update all active channel information\ntwitch_update();\n\n// Removes an active channel; you will not be able to use the data from this channel until requesting it again\ntwitch_remove( channel_id );\n\n// Free the data structures and sprites used by this API, call when you want to stop using it\ntwitch_free();\n\n// Used internally. You will probably never use this script, up until the heat death of the universe.\ntwitch_parse();\n```\n\n___\n\nHave fun with it guys!\n","funding_links":[],"categories":["Integrations"],"sub_categories":["Recommendations"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGameMakerDiscord%2FGMTwitch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGameMakerDiscord%2FGMTwitch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGameMakerDiscord%2FGMTwitch/lists"}