- Title: How to collect tweets from a Twitter user natively in GM
- Description: "this tutorials shows how to... etc"
- GM Version: GM:S 1.4.1567, compatible with 1.4.1690 and YYC
- File Type: .zip containing .gmz project file and .exe example
- File Size: ~2mb
- File Link: https://www.dropbox....PUBLIC.zip?dl=0
- Tags: Twitter, REST, RESTful, HTTP, http_request
Twitter has a very well documented REST API
that details how to use HTTP requests
to get data from their servers. This means you do can the following:
1. Recall a specific tweet.
2. Get up to 3,200 tweets from a user.
3. Read the home page of a user.
4. Get a list of friends or followers of a user.
Quick note - To actually post things to Twitter, you need to use url_open
alongside Twitter's intents API
. Making tweets from within an application is in theory possible but requires all kinds of OAuth shenanigans and/or a specific registration with Twitter under their xAuth programme
. This is outside the scope of this example.
What is in this example is a fully extensible framework for obtaining authorisation from Twitter, sending requests to Twitter using a single line of code, and an implementation of this framework to read tweets from a single user and obtaining tweets that contain a particular hashtag.
How does this work? It's a four step process:
- Set up the framework and add some callback scripts.
- Get an authorisation token from Twitter (automatically handled by the framework).
- Send a request to Twitter.
- Send the JSON response from Twitter to a callback script (automatic) and traverse the JSON to extract data.
In this example, only one part of the REST API has been implemented - GET statuses/user_timeline
under the scr_tweet_readout
In order to start using this framework in your projects, you'll first need to register as a Twitter developer
, add a new application and collect your key and secret. These are under "Keys and Access Tokens" on your application's page. Once you've pasted the key and the secret into the scr_juju_twitter_init
script, you're good to go.
Use scr_juju_twitter_request_general to make general calls through the framework to Twitter's API and add callback scripts to scr_juju_twitter_add_callback so that the framework knows where to route JSON data once it's been received.
scr_juju_twitter_http_async has a series of report levels (0 through 3) so that you can keep tabs on exactly how things are working. This script is also modifiable to add more backend functions in the framework should you feel you need them.
This example is released under the MIT License:
Copyright (c) 2016 Julian T. Adams / @jujuadams
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Edited by Juju, 22 January 2016 - 05:41 PM.