Jump to content


Photo
- - - - -

How to collect tweets from a Twitter user natively in GM


  • Please log in to reply
2 replies to this topic

#1 Juju

Juju

    GMC Member

  • GMC Member
  • 1109 posts
  • Version:Unknown

Posted 21 January 2016 - 07:44 PM

 
  • 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.
 
5. etc.
 
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:

 

  1. Set up the framework and add some callback scripts.
  2. Get an authorisation token from Twitter (automatically handled by the framework).
  3. Send a request to Twitter.
  4. 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 callback script.
 
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.

  • 3

Come find me @jujuadams

 

Try out my open-source 3D globe terrain generator!

How about a fancy-pants text engine?

Adding dialogue boxes to your games is now super easy. Also localisation. Also tweening.


#2 chance

chance

    GMC Member

  • Global Moderators
  • 8762 posts
  • Version:GM:Studio

Posted 22 January 2016 - 02:52 AM

This is a neat idea, and I'm sure enterprising designers can find applications for it. 
 
However, the zip file only contains the .exe, not the .gmz project file.  Just an oversight, I'm sure.  So I'll leave this here in Tutorials so you can fix the download.

 

EDIT:  I just re-checked, and the zip file now contains both the .exe example and the .gmz project file. 
 
This example isn't for beginners.  But the scripts are organized with descriptive text for each one.   So intermediate programmers willing to dig in and read carefully should be able to follow it.   And Juju provides links to Twitter's API documentation for reference.
 
This is an excellent addition to the Tutorials forum.


  • 0

#3 Juju

Juju

    GMC Member

  • GMC Member
  • 1109 posts
  • Version:Unknown

Posted 22 January 2016 - 05:42 PM

New version that fixes a couple of bugs (YYC *shakes fist*) and adds another implementation for search for a particular hashtag.


  • 0

Come find me @jujuadams

 

Try out my open-source 3D globe terrain generator!

How about a fancy-pants text engine?

Adding dialogue boxes to your games is now super easy. Also localisation. Also tweening.