Pages: 1 2 3 [4]   Go Down
Author Topic: Made my own TwitterClient and I think it's better than the example one  (Read 11504 times)
0 Members and 1 Guest are viewing this topic.
South UK
Offline Offline
God Member
*****
Karma: 2
Posts: 568
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi JO3RI, many thanks for the work!

Just testing it out and it only seems to return one tweet? I am pulling tweets from https://twitter.com/BBCBreaking to return latest news items but it only returns the latest, and after that it just keeps looking but not returning tweets?

Maybe I misunderstand something, but I have tried it with other usernames and it seems the same?

Is there also a way to display my twitter feed (to display tweets from those I'm following)?

Again, thanks smiley
Logged

Sweden
Offline Offline
Jr. Member
**
Karma: 0
Posts: 77
Arduino System Go!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there also a way to display my twitter feed (to display tweets from those I'm following)?

What you are looking for is the Home Timline
https://dev.twitter.com/docs/api/1/get/statuses/home_timeline
Logged

Hamme, Belgium
Offline Offline
Sr. Member
****
Karma: 4
Posts: 386
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The way I have set-up this client, it only shows the last tweet, it does 't get pushed on every new tweet. It just checks the time-line every x seconds and shows that tweet.

Hope that answers your question.
« Last Edit: February 05, 2013, 07:48:48 am by JO3RI » Logged


Murcia, Spain
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

are you able to show those characters on the serial monitor, when put into a string? (not from twitter, but when you just do Serial.print("those special characters"); ?

You can replace those &#241 , &#191, &#161 with the actual character. I did that in another project of mine (www.jo3ri.be/arduino/projects/castduino). You can start looking for &# with Textfinder and when found replace those with along with the according number.

Something like if &# and 241 than you have ñ.

also check google on "string replace" (http://www.cplusplus.com/reference/string/string/replace/)

Thanks for reply so fast JO3RI.
Well, I've opened a new sketch just to test this character (ñ):
Code:
char inChar1 = 'ñ';
char inChar2[] = {'ñ'};
char inChar3[] = "ñ";
char inChar4 = 241;
String inString = "ñ";

void setup()
{
  Serial.begin(9600);
 
  Serial.println("ñ");
  Serial.println(char(241));
  Serial.println(inChar1);
  Serial.println(inChar2);
  Serial.println(inChar3);
  Serial.println(inChar4);
  Serial.println(inString);
}

void loop()
{
}

Results:
Serial.println("ñ");  prints  ñ
Serial.println(char(241));  prints  ñ
char inChar1 = 'ñ';         Serial.println(inChar1);  prints  ±
char inChar2[] = {'ñ'};   Serial.println(inChar2);   prints  ±Ã±
char inChar3[] = "ñ";     Serial.println(inChar3);  prints  ñ
char inChar4 = 241;       Serial.println(inChar4);  prints  ñ
String inString1 = "ñ";     Serial.println(inString1);  prints  ñ
String inString2 = String(char(241));   Serial.println(inString2);  prints  ñ

I understand all of your code and it works, and I assure you I've been testing for days how to implement the replacement of those html characters and everything I'm testing doesn't work. Please, could you give me a hand and be a bit more explicit? This is the project for my degree smiley-wink Thanks.

PD: I changed the format from .rss to .xml and obviously the strings StartHere, EndHere, etc...
Logged

Hamme, Belgium
Offline Offline
Sr. Member
****
Karma: 4
Posts: 386
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What I did was this:
Code:
byte b = 0;
for (byte i = 0 ; i < 81 ; i++){   //this buffer is only 80 characters
  byte txt1 = buffer[i + b];      //look at the first character
  byte txt2 = buffer[i + b + 1]; //look at the second character
  byte txt3 = buffer[i + b + 2]; //look at the third character
  // lets make some of those special html characters readable
  if (txt1 == '%')
  // if you find an %, we will start looking for de second and tirth character
  // than we recalculate those into a new char en replace txt1 with the new one
  {
    char ascii[17] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
    for (byte c = 2; c < 8; c++){
      for (byte d = 0; d < 17; d++){
        if (txt2 == ascii[c] && txt3 == ascii[d]){
          txt1 = 32 + (((c-2)*16)+d);  //recalculate 2 separate HEX to one new
          b= b + 2; // go the the next character and therefore skip 2
        }
      }
    }
  }
}

But you will not be able to use it as is (it only replaces 2 HEX characters into 1 new)

To help you further, post me your twitter buffer (tweet) as you get it on your console. Second I need to know if in your buffer (tweet) this "&#241" takes 5 places or 3. Because we need to know if 241 is one character or three (2,4,1). if it is three, you'll have to do something like this:

Code:
txt1 = (txt3*100) + (txt4*10) +txt5)

it might be as simple as to look for:
Code:
if (txt1 == '&') && (txt2 =='#')
{
  txt1 = (txt3*100) + (txt4*10) +txt5)
}
and do this for all characters in your buffer (see first code in this post) and combine (don't forget to skip 4 places instead of 2, and don't forget your tweet buffer is 140 not 80, and you'll probable need txt1 till txt5)

On the other hand you could use textfinder on your "tweet" buffer and look for &#241 and replace it with '241' (1 character)

oh, and could you post the twitter account that posts those funny Spanish characters?
« Last Edit: February 05, 2013, 09:46:14 am by JO3RI » Logged


Murcia, Spain
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To help you further, post me your twitter buffer (tweet) as you get it on your console.

This part of my code:
Code:
while (client.connected())
    {
      if (client.available())
      {
        Serial.println(F("Obteniendo tweet..."));    
        if ( (finder.find("</id>")) && (finder.getString("<text>", "</text>", tweet, 150)!=0) )
        {
           if ( (finder.find("</name>")) && (finder.getString("<screen_name>", "</screen_name>", usuario, 50)!=0) )
           {
             Serial.print("@");
             Serial.print(usuario);  //Imprime el Usuario
             delay(1);
             Serial.print(">");
             delay(1);
             Serial.println(tweet);  //Imprime el Tweet
           }
        }  
      break;
    }
  }

prints this:
Code:
Obteniendo tweet...
@tuitduino>Probando la &#241; la &#191; y la &#161; por ejemplo.

But it should print this:
Code:
Obteniendo tweet...
@tuitduino>Probando la ñ la ¿ y la ¡ por ejemplo.

Quote
Second I need to know if in your buffer (tweet) this "&#241" takes 5 places or 3. Because we need to know if 241 is one character or three (2,4,1).
It is "&#241;" with an ;
It takes 6 places, one for every value you see (I've tested it), so "241" are three and "&#241;" are six.

Quote
On the other hand you could use textfinder on your "tweet" buffer and look for &#241 and replace it with '241' (1 character)
I've tried to do that by creating a new object
TextFinder replace(¿tweet?, 2)
and then looking for "&#241;" as it follows
if ( replace.find("&#241;") )
but I don't know how to replace "&#241;" into the buffer (tweet) smiley-mad smiley-cry So I'm going to attempt to do it the other way you mentioned before between quotes.

Quote
oh, and could you post the twitter account that posts those funny Spanish characters?
Well... I've created a Twitter account specialy for this purpose and my target is getting tweets from Spanish users, for this reason I have all of this troubles...

PD: many thanks again and I promise I will mention you in my code smiley-wink
« Last Edit: February 05, 2013, 04:58:14 pm by G3RMiCH » Logged

Hamme, Belgium
Offline Offline
Sr. Member
****
Karma: 4
Posts: 386
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Because this a Gallery topic, It will be better to ask your question in an other Forum part. Just ask your question in the Programming Questions.

How to convert  this:
Code:
char tweet[]="Probando la &#241; la &#191; y la &#161; por ejemplo.";
into this:
Code:
char tweet[]="Probando la ñ la ¿ y la ¡ por ejemplo.";

Put a link to your question here.

Please don't keep asking your questions here, make a new topic
Logged


South UK
Offline Offline
God Member
*****
Karma: 2
Posts: 568
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The way I have set-up this client, it only shows the last tweet, it does 't get pushed on every new tweet. It just checks the time-line every x seconds and shows that tweet.

Hope that answers your question.

Hi JO3RI, thanks for explaining that to me. is there a way to change the behaviour to show say the 10 latest tweets, and to update if a new one is posted?

Thanks for all your efforts!
Logged

Hamme, Belgium
Offline Offline
Sr. Member
****
Karma: 4
Posts: 386
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Hi JO3RI, thanks for explaining that to me. is there a way to change the behaviour to show say the 10 latest tweets, and to update if a new one is posted?

Well, If you that every tweet would have to be placed into a buffer in SRAM and every buffer is 140 bytes x 10 times is 1400 bytes only for those tweetbuffers (you only have 2048) and you need some for the libraries too.

You could use only 1 buffer and flow 10 tweets through it, but than you can't compare if it is a new tweet or not. To check if a new tweet is posted, I think you can only check periodically and compare the tweets you have, with the once you just checked.

This Arduino Client just asks the tweet stream, gets all of it and starts looking for the last tweet (the top) one, every 60 seconds.
try this in the url of your browser for a tweet account:

https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=JO3RI&count=1%20HTTP/1.1

and this for a hashtag:

http://search.twitter.com/search.atom?q=%23arduino

you'll see you have to refresh your browser to get an update

Maybe now you'll understand the problems to overcome. If you are going to try this, please ask your questions in the programming section, splitting your problem into small problems and try to tackle one at a time.

Have fun
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

With the requirement from Twitter to use their new api, this code does not work - returns the error page.

Does anyone have updated code that can used with the new Twitter api?
Logged

Murcia, Spain
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

With the requirement from Twitter to use their new api, this code does not work - returns the error page.

Does anyone have updated code that can used with the new Twitter api?

Sure! Look these links.:
https://dev.twitter.com/discussions/15078
http://stackoverflow.com/questions/12916539/simplest-php-example-for-retrieving-user-timeline-with-twitter-api-version-1-1?answertab=votes#tab-top
https://github.com/J7mbo/twitter-api-php
Logged

Pages: 1 2 3 [4]   Go Up
Jump to: