Pages: [1]   Go Down
Author Topic: Twitter again: search.twitter  (Read 2042 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 52
... indessen wandelt harmlos droben das Gestirn
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm stuck. I want to write an application which does a search on twitter. I have an ethernet shield and use the dns library. On the page apiwiki.twitter Twitter-Search-API-Method"it is said that the search API doesnt need the oAuth. And oAuth is a pain if you not know how to do Processing.

My question follows for I am not allowed to post URLs in my first msg  smiley-wink
Logged

---
... indessen wandelt harmlos droben das Gestirn

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 52
... indessen wandelt harmlos droben das Gestirn
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm stuck. I want to write an application which does a search on twitter. I have an ethernet shield and use the dns library. On the page "http://apiwiki.twitter.com/w/page/22554756/Twitter-Search-API-Method:-search" it is said that the search API doesnt need the oAuth.

When I formulate the query:
Code:
 if (client.connect()) {
      Serial.println("connected");
      client.println("GET /search.atom?q=help");
      client.println();

I get the result :
Code:
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://search.twitter.com/search.atom?q=help">here</a>.</p>
When I copy this URL  into the browser I get the correct results.

So my question: How could I encode the URL "http://search.twitter.com/search.atom?q=help" in the Arduino programm so that the string provokes the connection to twitter and triggers the search?

Thanks in advance  smiley-wink
Logged

---
... indessen wandelt harmlos droben das Gestirn

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

The GET request gets sent to the server that the client connected to. Which server are you connecting to? The correct server is, obviously, search.twitter.com.
Logged

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 52
... indessen wandelt harmlos droben das Gestirn
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

yes, it is search.twitter.com with dns resolution. It also doesnt work with the correct static address of search.twitter.

Thanks
Logged

---
... indessen wandelt harmlos droben das Gestirn

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So my question: How could I encode the URL "http://search.twitter.com/search.atom?q=help" in the Arduino programm so that the string provokes the connection to twitter and triggers the search?

You will need to use ethernet code that supports DNS resolution of the IP address. Below is some code I've used for simple testing that uses a special ethernet library.

Code:
//zoomkat 11-13-10
//Kegger ethernet client with DHCP/DNS test code
//using the Kegger ethernet library
//for use with IDE 0021 and W5100 ethernet shield
//open serial monitor to see what the arduino receives
//push the shield reset button to run client again
// http://kegger.googlecode.com/files/Ethernet.zip

#include <Ethernet.h>
#include "Dhcp.h"
#include "Dns.h"

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
boolean ipAcquired = false;

DnsClass googleDns;

void setup()
{
  Serial.begin(9600);
  
  Serial.println("getting ip...");
  int result = Dhcp.beginWithDHCP(mac);
  
  if(result == 1)
  {
    ipAcquired = true;
    
    byte buffer[6];
    Serial.println("ip acquired...");
    
    Dhcp.getMacAddress(buffer);
    Serial.print("mac address: ");
    printArray(&Serial, ":", buffer, 6, 16);
    
    Dhcp.getLocalIp(buffer);
    Serial.print("ip address: ");
    printArray(&Serial, ".", buffer, 4, 10);
    
    Dhcp.getSubnetMask(buffer);
    Serial.print("subnet mask: ");
    printArray(&Serial, ".", buffer, 4, 10);
    
    Dhcp.getGatewayIp(buffer);
    Serial.print("gateway ip: ");
    printArray(&Serial, ".", buffer, 4, 10);
    
    Dhcp.getDhcpServerIp(buffer);
    Serial.print("dhcp server ip: ");
    printArray(&Serial, ".", buffer, 4, 10);
    
    Dhcp.getDnsServerIp(buffer);
    Serial.print("dns server ip: ");
    printArray(&Serial, ".", buffer, 4, 10);
    
    
    //// Do DNS Lookup
    
    googleDns.init("web.comporium.net", buffer);  //Buffer contains the IP address of the DNS server
    googleDns.resolve();
  
    int results;
      
    while(!(results=googleDns.finished())) ;  //wait for DNS to resolve the name
    
    if(results != 1)
    {
      Serial.print("DNS Error code: ");
      Serial.print(results,DEC);
    }
    
    
    googleDns.getIP(buffer);  //buffer now contains the IP address for google.com
    Serial.print("Web Server IP address: ");
    printArray(&Serial, ".", buffer, 4, 10);
    
    Client client(buffer, 80);
    
    Serial.println("connecting...");

    if (client.connect()) {
      Serial.println("connected");
      client.println("GET /~shb/arduino.txt HTTP/1.0");
      client.println();
    
      while(true){  
        if (client.available()) {
          char c = client.read();
          Serial.print(c);
        }

        if (!client.connected()) {
           Serial.println();
           Serial.println("disconnecting.");
           client.stop();
           spinForever();
        }
      }  // while(true)
      
    
    
    } //if(client.connect())  
    else {
      Serial.println("connection failed");
    }
  }
  else
    Serial.println("unable to acquire ip address...");
}

void printArray(Print *output, char* delimeter, byte* data, int len, int base)
{
  char buf[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  
  for(int i = 0; i < len; i++)
  {
    if(i != 0)
      output->print(delimeter);
      
    output->print(itoa(data[i], buf, base));
  }
  
  output->println();
}

void loop()
{
    spinForever();
}

void spinForever()
{
  for(;;)
      ;
}

Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 52
... indessen wandelt harmlos droben das Gestirn
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

this is exactly what I have done:

The DNS lookup resolves the IP address correctly, but when i change the Program to

Code:
 if (client.connect()) {
      Serial.println("connected");
      client.println("/search.atom?q=help");
      client.println();
or
Code:
 if (client.connect()) {
      Serial.println("connected");
      client.println("search.atom?q=help");
      client.println();
instead of
Code:
client.println("GET /search.atom?q=help");

I receive
Code:
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://search.twitter.com/">here</a>.</p>

So when the arduino makes the connection, there seems to be some sort of acknowledgement. So my string is interupted:

Code:
http://search.twitter.com ??? /search.atom?q=help

and I cant trace the code on the ethernetport  smiley-sad
Logged

---
... indessen wandelt harmlos droben das Gestirn

Pages: [1]   Go Up
Jump to: