Programming Documentation
Programming Documentation
By Max Dovey
12/04/2011
There are 3 parts that connect for this real time visualization to
work.
Brief
I want to monitor expressions on twitter that use terms that define
individual emotions. I want to be bale to visually present real time
use of these terms in a graphically way.
1st stage
Getting code that can respond and interact with Twitter
Installation
I began by downloading the Twitter4j library and importing it into
Processing. This was not that easy
My Sketch still refused to work saying that it cannot find the
Twitter4j Library.
I then posted an example code into the sketch and uploaded into
the forum.
hey been using this code to get twitter4j working but keep getting this error
saying unexpected character "\" but this character doesn't exist in the code
so i don't really get it.
it also says:
processing.app.debug.RunnerException: unexpected char: '\'
at processing.app.Sketch.preprocess(Sketch.java:1352)
at processing.app.Sketch.preprocess(Sketch.java:1205)
at processing.app.Sketch.build(Sketch.java:1568)
at processing.app.Sketch.build(Sketch.java:1553)
at processing.app.Editor$DefaultRunHandler.run(Editor.java:1485)
at java.lang.Thread.run(Thread.java:680)
Copy code
1. /*
2. Posts a message to a Twitter account when you press the mouse
button.
3. Uses Twitter4j, http://twitter4j.org.
4. For more info: http://tinkerlondon.com/now/2010/09/13/oauth-
twitter-and-processing/
5. Daniel Soltis, September 2010
6. */
7. import twitter4j.conf.*;
8. import twitter4j.internal.async.*;
9. import twitter4j.internal.org.json.*;
10. import twitter4j.internal.logging.*;
11. import twitter4j.http.*;
12. import twitter4j.api.*;
13. import twitter4j.util.*;
14. import twitter4j.internal.http.*;
15. import twitter4j.*;
16. String msg = “Automatically posted from Processing”;
17. //copy and paste these from your application in
dev.twitter.com
18. String consumer_key =
“publicconsumerkeyfromtwitterdevpage”;
19. String consumer_secret =
“secretconsumerkeyfromtwitterdevpage”;
20. String oauth_token = “accesstokenforyouraccount”;
21. String oauth_token_secret =
“secretaccesstokenforyouraccount”;
22. color bgcolor = color(255);
23. long timer;
24. void setup() {
25. size(640,480);
26. }
27. void draw() {
28. background(bgcolor);
29. if (millis()-timer > 2000) bgcolor = color(255);
30. }
31. void mousePressed() {
32. Twitter twitter = new
TwitterFactory().getOAuthAuthorizedInstance (
33. consumer_key, consumer_secret,
34. new AccessToken( oauth_token, oauth_token_secret) );
35. try {
36. Status st = twitter.updateStatus(msg + ” ” + second());
37. println(“Successfully updated the status to [" + st.getText()
+ "].”);
38. bgcolor = color(0,0,255);
39. timer = millis();
40. }
41. catch (TwitterException e) {
42. println(e.getStatusCode());
43. }
44. }
1 user has this question
14/04/11
processing version 1.2.1 deleted
Connection made
14/04/10
Now I managed to run an app that tweeted when I clicked my
mouse – I got slightly overexcited
License
Before I quickly over-used the Twitter API I had to register before
they blocked me for spamming the site.
This authentication for third party clients (tweeting without twitter)
only came to practice last summer. Its an act of data security on
Twitters part. So I tried to register on the devlopers site for Twitter.
http://dev.twitter.com/
Searching
I then slammed in the earlier code that searches twitter.
This works, you can set the amount you retrieve for various search
terms. I searched 100 happy and 100 sad. See here.
Problems with this code is that it wont fetch more than 100 per
query.
how to accurately
I began to encounter my next issue,
portray the amount of emotional
expressions in realtime
Twitter has strict rules and what you do with the data. Below are restrictions
on third party use.
Anonymous calls are based on the IP of the host and are
permitted 150 requests per hour. This classification includes
unauthenticated requests (such as RSS feeds), and
authenticated requests to resources that do not require
authentication.
OAuth calls are permitted 350 requests per hour.
That’s 6 a minute
1 every 10 secs
Problems –
Pretty happy but….
All search terms begin fast and exciting when there is 100
or less tweets. Once you get to 1000 they remain static
due to their size. When analyzing emotional data it seems
to all become static, meaning there is constant
expressions of basic emotional categories on Twitter. I
can use more search terms in one label to widen my
search, but perhaps all subjective feelings become mass
quantified in a constant stream?
I have to address this. It makes all personal expressions
turn into categorized, quantified null data. Does this fit with
what I am trying to convey?
The value of social media as a device for expression
and its possibility to measure wellbeing.
Also this code does not ask for username/ password and
other Security details. I have run it for 30 mins without
problems. I want to know why it doesn’t require security
authorization and is this a risk?
API methods which are not directly rate limited are still subject to
organic, unpublished limits. This includes actions like publishing
status updates, direct messages, follow/unfollow actions, etc.
These Twitter Limits are described on our help site.
and http://www.twitter.com.
helm's-alee will return statuses which contain: helm’s-alee
to Twitter”.
chirp search,chirp streaming will return statuses such as: “Listening to
http://dev.twitter.com/pages/streaming_api_concepts
Conclusion
The streaming Twitter part of the emotional stock market
was always going to be hard. Luckily I located a lot of
guides online and teachings from people better at
computer programming than me. I have customized a bar
graph for counting tweets and have also got a stream bar
that shows every tweet using that word. Fortunately it was
important to remember this was a piece of art, not social
science and could therefore be ambiguous. Its more
important to give the impression that every tweet is being
counted, than doing it.
Processing forum –
http://forum.processing.org/