Pages: [1]   Go Down
Author Topic: Not receiving the latest tweet  (Read 568 times)
0 Members and 1 Guest are viewing this topic.
Singapore
Offline Offline
Jr. Member
**
Karma: 0
Posts: 63
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, has anybody encountered this problem when you retrieve tweet you don't get the latest.
The tweet received could be the 3rd last message on the twitter server.
It just received the 2nd last message after some time but until now still not receiving the last message.

I have checked using the web browser and the last message is already on the twitter server.

Anybody can advise me
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Anybody can advise me
I could advise you to post your code.
Logged

Singapore
Offline Offline
Jr. Member
**
Karma: 0
Posts: 63
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My codes looks like this:



void connectToServer()
{
   Serial.println("Connecting to Twitter server...");
      if (client.connect(Twitterserver, 80))
        {
        Serial.println("making HTTP request...");
        client.println("GET /1/statuses/user_timeline.xml?id=lawrence_tay HTTP/1.1");
        client.println("HOST: api.twitter.com");
        client.println();   
        client.println("Connected...");
        }
        else
        {
          Serial.println("connection failed");
        }


boolean retrieveTweet()
{
if (client.connected())                               // Whether or not the client is connected.
    {
     if(finder.getString("<text>","</text>",tweet,50)!=0 )     // Finds text "temp=" in weather Yahoo XML page source
      { 
        Serial.print("Message:  ");
        Serial.println(tweet);
        textArea.ClearArea();       
        textArea.CursorTo(0, 0);
        textArea.print(tweet);
        return true;
      }
      else
      {
        Serial.println("No message");
        textArea.ClearArea();
        return false;
      }
    client.stop();
    client.flush();
    }
}
Logged

Singapore
Offline Offline
Jr. Member
**
Karma: 0
Posts: 63
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To add on, I am trying to look for a key word in the latest tweet before I carry out some actions. How can I do that?

Currently I have the following codes to look for tweet that begins with "stat:"

If the tweet contains this keyword it will retrieve the tweet following the word "stat:". However if the latest tweet does not have the keyword, it will continue and end up retrieving the older tweet with the keyword "stat:"

For example, I tweet "stat: Testing". It will retrieve and print "Testing"
then I tweet "Next Test" without keyword "stat:"
it will still retrieve and print "Testing" because that is the tweet with the keyword.
I only wants it to check the latest tweet, if with keyword - retrieve and print text following "stat:" and if without keyword - print no message


boolean retrieveTweet()
{
if (client.connected())                               // Whether or not the client is connected.
    {
     if(finder.getString("<text>stat:","</text>",tweet,50)!=0 )     // Finds text "temp=" in weather Yahoo XML page source
      { 
        Serial.print("Message:  ");
        Serial.println(tweet);
        textArea.ClearArea();
       
        textArea.CursorTo(0, 0);
        textArea.print(tweet);
       
        return true;
      }
      else
      {
        Serial.println("No message");
        Serial.println(tweet);
        textArea.ClearArea();
        //Serial.println(tweet);
        return false;
      }
    client.stop();
    client.flush();
    }
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if(finder.getString("<text>","</text>",tweet,50)!=0 )     // Finds text "temp=" in weather Yahoo XML page source
Does it really?
Logged

Singapore
Offline Offline
Jr. Member
**
Karma: 0
Posts: 63
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, it works. I include another level of checking so it won't skip the latest tweet if it does not have the keyword.



if(finder.getString("<text>","</text>",tweet,50)!=0 )     // Finds text "temp=" in weather Yahoo XML page source
      { 
        test = 0;
        for(i = 0; i<4; i++)
          {
            if(tweet == stat)                        //check if the first 5 char = "stat:"
              {
                test += 1;
                Serial.print("Test: ");
                Serial.println(test);
                Serial.println(tweet);
                Serial.println(stat);
              }
          }
      }
         if (test > 5)                        //it is a user status
           {
            if(finder.getString("<text>stat:","</text>",tweet,50)!=0 )
              {
              Serial.print("Message:  ");
              Serial.println(tweet);
              textArea.ClearArea();
       
              textArea.CursorTo(0, 0);
              textArea.print(tweet);
              return true;
              }
            }
          else
            {
              Serial.println("No message");
              Serial.println(tweet);
              textArea.ClearArea();
              return false;
            }
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if(finder.getString("<text>","</text>",tweet,50)!=0 )     // Finds text "temp=" in weather Yahoo XML page source
That code does NOT find temp= in the weather Yahoo XML page.
Logged

Singapore
Offline Offline
Jr. Member
**
Karma: 0
Posts: 63
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry the remarks is not correct.

Seems like it still does not work well
Logged

Singapore
Offline Offline
Jr. Member
**
Karma: 0
Posts: 63
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I am still not receiving the latest tweet. Please help me

I have attached a photo of my tweet messages.

What happened is:

When my latest tweet is "No sweat", the code will not retrieve any message --- that's correct as per the code.

But when my latest tweet is "stat: Testing onboard", the code will retrieve the message but not the latest. It will retrieve "Working again".

I have attached my codes as follows:


boolean retrieveTweet()
{
if (client.connected())                               // Whether or not the client is connected.
    {
     if(finder.getString("<text>","</text>",tweet,50)!=0 )     // Finds text "temp=" in weather Yahoo XML page source
      { 
        test = 0;
        for(i = 0; i<5; i++)
          {
            if(tweet == stat)                        //check if the first 5 char = "stat:"
              {
                test += 1;
                Serial.print("Test: ");
                Serial.println(test);
                Serial.println(tweet);
                Serial.println(stat);
              }
          }
      }
         if (test > 4)                        //it is a user status
           {
            if(finder.getString("<text>stat:","</text>",tweet,50)!=0 )
              {
              Serial.print("Message:  ");
              Serial.println(tweet);
              textArea.ClearArea();
       
              textArea.CursorTo(0, 0);
              textArea.print(tweet);
              return true;
              }
            }
          else
            {
              Serial.println("No message");
              Serial.println(tweet);
              textArea.ClearArea();
              return false;
            }
    client.stop();
    client.flush();
    }
}


* tweet.png (183.07 KB, 640x960 - viewed 14 times.)
Logged

Pages: [1]   Go Up
Jump to: