Ethernet and facebook

Hello there!

I started playing around with the Ethernet shield and tried some examples in order to learn the basics.

I tried Google searches and stuff like that and everyting ran well.

I´ve seen some projects that connect to facebook and retreive info from it but no code at all just videos or images.

What I would like to do is just get raw info to start with something. For example connect to graph.facebook.com/someID and get the whole thing as plain text just like you do when using the DnsWebClient sketch asking Google to search "arduino".

Now the problem I have is that I can´t connect properly. I´m using the DnsWebClient sketch as a basis just changing the server to "graph.facebook.com" and then asking "GET /someID HTTP/1.0".

Any tip is most welcomed!

For example connect to graph.facebook.com/someID and get the whole thing as plain text

So, do it. The "plain text" will likely be HTML, but HTML is text.

Now the problem I have is that I can´t connect properly.

We can't see your code. We can't see the output, if any, that your program produces. And, yet, you'd like us to use our crystal balls to tell you what the problem is.

I think we need just a bit if a hint. Or more.

Sorry for the lack of info.

Here is the code I´m using:

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; //not the real mac
char serverName[] = "graph.facebook.com";

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup(){
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
while(true);
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println(Ethernet.localIP());
Serial.println("connecting...");

// if you get a connection, report back via serial:

if (client.connect(serverName, 80)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /40796308305 HTTP/1.0");
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
}

void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
}

// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();

// do nothing forevermore:
while(true);
}
}

And this is what it reports back:

XXX.XXX.XXX.XXX // it reports a proper IP
connecting...
connected
HTTP/1.0 301 Moved Permanently
Location: Redirecting...
Content-Type: text/html; charset=utf-8
X-FB-Debug: GvknnluCEGIMnhqIRXmZ2dYZptRrEpwtZQcqBRZBT88=
Date: Sun, 14 Oct 2012 02:35:37 GMT
Connection: close
Content-Length: 0

disconnecting.

Is there some part of this:

HTTP/1.0 301 Moved Permanently

that you can't google?

PaulS:
Is there some part of this:

HTTP/1.0 301 Moved Permanently

that you can't google?

I´ve searched that but the report does not tell me where to head in order to get what I want.

If you type in a web browser "graph.facebook.com/40796308305" (using cocacola as an example) you get a summary of info.

I would like to retreive that information just as I would do with the basic sketch where you ask Google to search "arduino".

Thanks a lot!

If you type in a web browser "graph.facebook.com/40796308305" (using cocacola as an example) you get a summary of info.

You get redirected to the new location, and then get some info. You 301 return code is telling you where the page moved to.

PaulS:

If you type in a web browser "graph.facebook.com/40796308305" (using cocacola as an example) you get a summary of info.

You get redirected to the new location, and then get some info. You 301 return code is telling you where the page moved to.

It tells me that the location is "Redirecting..." but that directs me to Coca Cola´s facebook page not to the original page I would like "graph.facebook.com/40796308305" that´s what troubles me.

I still can't make this work. Any tip? It seems so simple that it's embarrasing not being able to figure out what I'm missing...

What I´ve found out is that when asking "GET /40796308305 HTTP/1.0" it actually lets you download a file ("40796308305.js" - a Json object, which in turns is just text) instead of opening a webpage. How can I handle it?

Thanks!

How can I handle it?

Tongs and fire suit?

How do you want to "handle" it?

I mean what should I do? or what am I doing wrong?

Starting over from the beginning.

If I use "www.google.com" as server and ask "GET /search?q=arduino HTTP/1.0" (using the basic example sketch) I get the result of the Google search. Great! I get information to interpret as I like.

If I use "graph.facebook.com" as server and ask "GET /40796308305 HTTP/1.0" what I get is an error message (the one I posted before that tells me to go to "Redirecting...", but that is Coca Cola's facebook page and not the graph info that I want).

I was usig Firefox to check "graph.facebook.com/40796308305" but it was interpreting and showing the contents of a file on screen (the contents of a Json file) Then I tried with Internet Explorer and that was when I realized there was a file being opened and shown to me by Firefox. IE asked me whether to download or open the file "40796308305.js"

I would like to retreive the info just as I would do it in the basic example.

Thanks a lot!

I was usig Firefox to check "graph.facebook.com/40796308305" but it was interpreting and showing the contents of a file on screen (the contents of a Json file) Then I tried with Internet Explorer and that was when I realized there was a file being opened and shown to me by Firefox. IE asked me whether to download or open the file "40796308305.js"

Interesting. I used Firefox, too, and I saw the same data that you did. Apparently, there is some redirection going on, and Firefox knows how to find, fetch, and interpret a .js file, while IE only knows how to find and fetch it.

Now, exactly how they are finding it, given that the direct request returns an error, is a mystery. The good news is that Firefox is open source, so all the source code is available, and you could hack through that to figure out how it is handling the initial 301 code. Not a trivial task, I'll assume.

Perhaps someone else knows. I'll admit I'm stumped.

I wonder, though, if the data you are after is available some other way. Or, perhaps, is not really intended for you to get at.

.js is a javascript file. I will presume the url is designed to be loaded into an iframe on another page. Just a guess.

Thaks for the replies! I'm still stuck with this. As soon as I get any result I will post it.

PaulS:
I wonder, though, if the data you are after is available some other way. Or, perhaps, is not really intended for you to get at.

As far as I've read that information is supposed to be freely available. I keep wondering how does Firefox manages to get the info. As you've said It seems not to be an easy task to figure that out.

SurferTim:
.js is a javascript file. I will presume the url is designed to be loaded into an iframe on another page. Just a guess.

I will keep that in mind!