Accessing Twitter
- go to apps.twitter.com and click the Create New App Button
- fill out the application details, the website can be a dummy address
- go to “Keys and Access Tokens” and click “Create my access token”
- get App Key, App Secret, User OAuth Token and User OAuth Secret from Consumer Key, Consumer Secret, Access Token and Access Token Secret
- set Authentication Type of the web Component to OAuth1 and fill in the parameters
connecting to Streaming API of Twitter:
For an overview of the available parameters refer to Twitter Documentation here
- on the Web Parameter Page of the COMP set Request type to “Post”, the URL to “https://stream.twitter.com/1.1/statuses/filter.json” and turn on the “Stream” parameter.
- add a Table DAT to the second Input of the COMP and specify any of the request parameters listed in the twitter api documentation
- toggle the “Activate” parameter and pulse the “Go” parameter. In the textport you should see messages coming in.
- the incoming data is send to the docked DAT called web1_callback. Here it literally just prints our a dictionary with the keys
[list]
[*]msg - status
- code
- encoding
[/:m]
[]while the stream is active there will only be the msg key and it’s value containing whatever comes down the stream[/:m]
[]to decode the twitter message enter this in the web1_callback DAT:
import json
def receive(data):
msg = data.get('msg',None)
if msg:
decoded = json.loads(msg.decode())
for k in decoded.keys():
print('key:',k,'value:',decoded[k])
return
[/:m][]to stop the stream, pulse the “Stop” parameter.[/:m]
[]changing the request parameters only takes effect after stopping and restarting the stream.[/*:m][/list:u]
connecting to REST API of Twitter:
For an overview of the available connection points refer to Twitter Documentation here
- To see the last tweets of a twitter account, choose the connection point GET statuses/user_timeline by entering the url api.twitter.com/1.1/statuses/user_timeline.json into the “URL” parameter of the COMP.
- Choose the GET type in the “Request Type” parameter.
- Turn of the “Stream” parameter
- add a Table DAT to the second Input of the COMP and specify any of the request parameters listed in the twitter api documentation (for example “screen_name”)
- Pulse the “Go” parameter
- To decode this response enter this code into the web1_callbacks DAT:
[code]import json
def receive(data):
msg = data.get(‘msg’,None)
if msg:
msg = msg.decode()
decoded = json.loads(msg)
for i in decoded:
print('-------------------------')
for k in i.keys():
print('key:',k,'value:',i[k])
return[/code]