We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › Processing and Twitter
Pages: 1 2 3 4 5 6
Processing and Twitter (Read 65231 times)
Re: Processing and Twitter
Reply #30 - Apr 14th, 2009, 10:33am
 
ok I feel real dumb, because its still not working Sad


here is my whole code:

Code:
Twitter twitter;
String myTimeline;
User[] friends;
String username = "username"; // add your own here
String password = "pass"; // add your own here
twitter = new Twitter(username,password);


try
{
java.util.List statuses = twitter.getUserTimeline();
}
    for( int i=0; i<statuses.size(); i++ )
    {
  Status status = (Status)statuses.get(i);
  println(status.getUser().getName() + ":" + status.getText());
    }

catch( TwitterException e) {
println(e.getStatusCode());
}


I'm guessing i've missed a } or something somewhere because I get the error Syntax error, insert "Finally" to complete TryStatement
Re: Processing and Twitter
Reply #31 - Apr 14th, 2009, 10:41am
 
The catch has to go straight after the try, not after some other code, i.e.:

Code:
try{
something();
}
catch(Exception e)
{
}
otherThings();


instead of:

Code:
try{
something();
}
otherThings();
catch(Exception e)
{
}
Re: Processing and Twitter
Reply #32 - Apr 14th, 2009, 11:01am
 
Thank you for all the help!
Re: Processing and Twitter
Reply #33 - Apr 28th, 2009, 10:40am
 
Smiley
Re: Processing and Twitter
Reply #34 - Apr 28th, 2009, 12:02pm
 
How is it going?  Smiley
Re: Processing and Twitter
Reply #35 - Apr 29th, 2009, 2:05am
 
Sorry for taking over this thread but i was following the last 2 pages hoping to learn how to use Twitter4j but i still get a few errors.

Im not familiar with Java (and when i say familiar i mean, i have no clue of what im doing) so bear with me  Tongue

Code:

Twitter twitter;
String myTimeline;
User[] friends;
String username = "myusername"; // add your own here
String password = "mypass"; // add your own here
twitter = new Twitter(username,password);

//java.util.List statuses = twitter.getUserTimeline();

try
{
java.util.List statuses = twitter.getUserTimeline();
}
catch( TwitterException e)
{
println(e.getStatusCode());
}
for( int i=0; i<statuses.size(); i++ )
{
Status status = (Status)statuses.get(i);
println(status.getUser().getName() + ":" + status.getText());
}

Cannot Find anything named statuses



and Processing highlights the } just after println(e.getStatusCode());
}



Im trying to understand how twitter4j works so i can start my own coding.

Thank you
Re: Processing and Twitter
Reply #36 - Apr 29th, 2009, 7:22am
 
that's just a scope problem - you define statuses within the try block so it's only available within that block.

you need to define it outside:

// define
java.util.List statuses;

try
{
 // set value
 statuses = twitter.getUserTimeline();
}
...
Re: Processing and Twitter
Reply #37 - Apr 29th, 2009, 8:52am
 
Code:


Twitter twitter;
String myTimeline;
User[] friends;
String username = "myusername"; // add your own here
String password = "mypass"; // add your own here
java.util.List statuses;
twitter = new Twitter(username,password);

try
{
statuses = twitter.getUserTimeline();
}
catch( TwitterException e)
{
println(e.getStatusCode());
}
for( int i=0; i<statuses.size(); i++ )
{
Status status = (Status)statuses.get(i);
println(status.getUser().getName() + ":" + status.getText());
}




Local variable statuses may not have been initialized
Re: Processing and Twitter
Reply #38 - Apr 29th, 2009, 9:01am
 
Code:
java.util.List statuses = null; 

Re: Processing and Twitter
Reply #39 - Apr 29th, 2009, 9:11am
 
Goodness Gracious it works... heres the Code
Code:


Twitter twitter;
String myTimeline;
User[] friends;
String username = "USERNAME"; // add your own here
String password = "PASSWORD"; // add your own here
java.util.List statuses = null;

twitter = new Twitter(username,password);
//java.util.List statuses = twitter.getUserTimeline();
try
{
statuses = twitter.getUserTimeline();
}
catch( TwitterException e)
{
println(e.getStatusCode());
}
for( int i=0; i<statuses.size(); i++ )
{
Status status = (Status)statuses.get(i);
println(status.getUser().getName() + ":" + status.getText());
}





Result:
A list of all the tweets made by that certain user.






Time to read and understand the code so I can re-do it for my purpose =D

thanks everyone, I shall keep this post updated with news.  Cool
Re: Processing and Twitter
Reply #40 - Apr 29th, 2009, 2:45pm
 
import simpleML.*;
import processing.serial.*;
int time;
String lasttweet;
String[] check;
String[] titulo;
Serial port;

Twitter twitter;
User[] friends;
String username = "USER"; // add your own here
String password = "PASS"; // add your own here
java.util.List statuses = null;

twitter = new Twitter(username,password);

void setup(){ //resets a few vars, sets frameRate to 1 for the draw and inits the port for future comunication with arduino (not implemented yet)
println("Starting timer..");
frameRate(1);
int time = 0;
lasttweet = " ";
port = new Serial(this, Serial.list()[1], 9600);
}

void draw() {
 background(0);
 time++;
 if (time>=4){
   tweets(); // should call tweets function and show all the tweets from the friends_timeline
   time=0;
 }
}

void tweets(){ //Should be working fine. At least it did before i placed it on a function "void tweets()"
 
try
 {
  statuses = twitter.getFriendsTimeline();
 }
 catch( TwitterException e)
 {
  println(e.getStatusCode());
 }
 for( int i=0; i<statuses.size(); i++ )
 {
    Status status = (Status)statuses.get(i);
    println(status.getText());
 }
}




Error:

unexpected token: void


at "void setup()"
Re: Processing and Twitter
Reply #41 - Apr 29th, 2009, 3:19pm
 
Fixed.

had to move twitter = new Twitter(username,password); inside setup().


So far so good.
Re: Processing and Twitter
Reply #42 - Apr 29th, 2009, 5:15pm
 
http://img300.imageshack.us/img300/2517/picture4v.png

any ideas?
Re: Processing and Twitter
Reply #43 - Apr 29th, 2009, 5:47pm
 
Fixed.

didnt use check = match(....);
instead:   if(tweet.length() != lasttweet.length()){...}
and it worked.

heres the code working 100%


Code:


import simpleML.*;
import processing.serial.*;
int time;
String lasttweet;
String tweet;
String[] check;
String[] titulo;
Serial port;
int rate;
String bla;

Twitter twitter;
User[] friends;
String username = "USER"; // add your own here
String password = "PASS"; // add your own here
java.util.List statuses = null;



void setup(){
twitter = new Twitter(username,password);
println("Starting timer...");
frameRate(1);
int time = 0;
lasttweet = " ";
port = new Serial(this, Serial.list()[1], 9600);
}

void draw() {
background(0);
println("tic-tac: " + time + "sec.");
time++;
if (time>=4){
tweets();
time=0;
}
}

void tweets(){

//Coloca a friend time line na var statuses
try
{
statuses = twitter.getFriendsTimeline();
}
catch( TwitterException e)
{
println(e.getStatusCode());
}

Status status = (Status)statuses.get(0);
tweet = status.getText();
println("Tweet actual: " + tweet);
println("Tweet Anterior: " + lasttweet);

//Mostra o rate limit
try
{
rate = twitter.rateLimitStatus().getRemainingHits();
println("Rate limit: " + rate);
}
catch( TwitterException e)
{
println(e.getStatusCode());
}

if (tweet.length() != lasttweet.length()){
println("==New Tweet==\n\n");
port.write('H');
}
else
{
println("==No Activity==\n\n");
port.write('L');
}

Status Lstatus = (Status)statuses.get(0);
lasttweet = Lstatus.getText();
}



Re: Processing and Twitter
Reply #44 - Apr 30th, 2009, 4:33pm
 
Ok. New Update.

Now i've made a small GUI so the user can insert the Username and password of his Twitter account. This makes it easy for anyone user "Birduino" http://cg-levelseven.blogspot.com/search/label/prt.sc wich is our school project. (videos and images available).
Code:

//############ Vars para Interface ###################
import controlP5.*;

ControlP5 controlP5;

int myColorBackground = color(30,30,30);
int corTitulo = color(40,100,155);
int corSubtitulo = color(54,132,55);
Textfield usernameTXB;
Textfield passwordTXB;
Textlabel tituloLABEL;
Textlabel subtituloLABEL;

//############ Vars para ligar ao Arduino e para o twitter ################

import simpleML.*;
import processing.serial.*;
int time;
String lasttweet;
String tweet;
String[] check;
String[] titulo;
Serial port;
int rate;
String bla;

Twitter twitter;
User[] friends;
String username;
String password;
//String username = "USERNAME";
//String password = "PASSWORD";

java.util.List statuses = null;

//FUNÇÃO PARA O SUBMIT DOS VALORES DAS CAIXAS DE TEXTO

void controlEvent(ControlEvent theEvent) {
username = usernameTXB.getText();
password = passwordTXB.getText();
//println("\n\n Username: "+ usernameTXB.getText() + "\nPassword: " + passwordTXB.getText());

}


void setup(){

//#########CONFIGURA O INTERFACE###############
size(400,300);
frameRate(30);
controlP5 = new ControlP5(this);
usernameTXB = controlP5.addTextfield("Username",100,160,200,20);
usernameTXB.setFocus(true);
passwordTXB = controlP5.addTextfield("Password",100,200,200,20);
passwordTXB.setPasswordMode(true);


subtituloLABEL = controlP5.addTextlabel("label","complete the following fields.",20,134);
subtituloLABEL.setColorValue(corSubtitulo);

tituloLABEL = new Textlabel(this, "Welcome to Birduino.",20,100,400,200,0xffff0000,ControlP5.synt24);
tituloLABEL.setLetterSpacing(3);
tituloLABEL.setColorValue(corTitulo);

//########## CONFIGURA A LIGAÇÃO AO TWITTER ###############
twitter = new Twitter(username,password);
println("Starting timer...");
int time = 0;
lasttweet = " ";
port = new Serial(this, Serial.list()[1], 9600);
}

void draw() {

//########## Desenhar o interface #################
background(myColorBackground);
tituloLABEL.draw(this);


//se as variáveis de utilizar e password não estiverem preenchidas, nao corre o timer
if(username != null && password != null){
//######## Timer para correr a função tweets(); ##########
//println("tic-tac: " + time + "sec.");
time++;
if (time>=120)
{
tweets();
time=0;
}
}
else
{
println("introduzir dados");
}
}


void tweets(){

//Coloca a friend time line na var statuses
try
{
statuses = twitter.getFriendsTimeline();
}
catch( TwitterException e)
{
println(e.getStatusCode());
}

Status status = (Status)statuses.get(0);
tweet = status.getText();
println("Tweet actual: " + tweet);
println("Tweet Anterior: " + lasttweet);

//Mostra o rate limit
try
{
rate = twitter.rateLimitStatus().getRemainingHits();
println("Rate limit: " + rate);
}
catch( TwitterException e)
{
println(e.getStatusCode());
}

if (tweet.length() != lasttweet.length())
{
println("==New Tweet==\n\n");
port.write('H');
}
else
{
println("==No Activity==\n\n");
port.write('L');
}

Status Lstatus = (Status)statuses.get(0);
lasttweet = Lstatus.getText();
}




Im having a small problem and i know why it is happening.
According to the debug, im getting a "no username or password was sent for authentication" or something like that to the following line  statuses = twitter.getFriendsTimeline();

This works fine if i uncomment the following lines:

//String username = "USERNAME";
//String password = "PASSWORD";

and give them a valid username / password. These vars will then be global to the program and when needed they will be set and sent to the function and everything works fine.

However whats happening is, the GUI i made should put the Username and Password on those variables in the following function:

void controlEvent(ControlEvent theEvent) {
 username = usernameTXB.getText();
 password = passwordTXB.getText();
 //println("\n\n Username: "+ usernameTXB.getText() + "\nPassword: " + passwordTXB.getText());
}


Problem is somewhere here... teh vars username and password arent  "global" or lose theyr value when they are requested by the function that needs them...


Any idea how i could make them global? and still be set by the user on the GUI?


Thank you Smiley
Pages: 1 2 3 4 5 6