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 › get data from the web - Facebook
Page Index Toggle Pages: 1
get data from the web - Facebook (Read 3192 times)
get data from the web - Facebook
May 17th, 2010, 12:32pm
 

Hello!

I try to use the Facebook-Site to get data.
If you are logged in you can get your friends via
https://graph.facebook.com/774/friends?access_token=ommitted.
where 774 is you FB-ID.
see
http://developers.facebook.com/docs/reference/api/

It returns

{
  "data": [
     {
        "name": "O P",
        "id": "5"
     },
     {
        "name": "M N".................
and so forth - works in the browser. That's what I want to get!
(doesn't look like xml to me...)

anyway.


I try this from a processing Application and I am stuck.

I try to use

Code:
String step0 = "https://graph.facebook.com/774/friends?access_token=ommitted.";
String step1 = "https://graph.facebook.com/778/picture?access_token=ommitted.";



XMLElement xml;

void setup() {
 size(200, 200);
 xml = new XMLElement(this, step0);

 println(xml.getContent()); // nothing
 // println(xml.getStringAttribute(url));

 int numSites = xml.getChildCount();
 for (int i = 0; i < numSites; i++) {
   XMLElement kid = xml.getChild(i);
   int id = kid.getIntAttribute("id");
   String url = kid.getStringAttribute("url");
   String site = kid.getContent();
   println(id + " : " + url + " : " + site);    
 }
}


It returns nothing.

So my question is
how can I receive the text with my friend's list in the processing Application.

Thanks!!

Chrisir  Wink

Re: get data from the web - Facebook
Reply #1 - May 17th, 2010, 1:15pm
 
That's not XML data, I believe it's JSON format.

http://www.json.org/java/ provides tools to use the data, and convert it to various formats (including XML)
Re: get data from the web - Facebook
Reply #2 - May 18th, 2010, 12:10pm
 


Hello,

Yes, it's JSON.

But I don't get the information on the link you posted.

What is the reader class there?

How can I get information like:
String result = getInformationFromURL (url1);

Thanks!

Chrisir   Wink

Re: get data from the web - Facebook
Reply #3 - May 19th, 2010, 3:23pm
 
From what I can tell, you'll need to use the JSONObject.java in your code, then create a JSONObject from the text, which you get with loadString("http://....") (though you'll need to concatenate all the strings returned into one string to pass to the JSONObject constructor.

When you've got the object, you just do String name=myJSONObject.getString("name");
Re: get data from the web - Facebook
Reply #4 - May 22nd, 2010, 6:05am
 
How can I download JSONObject.java?
How do I make it part of my program? Is it a library?

Can you post soe code, please?

Thanks!

Chrisir   Wink
Re: get data from the web - Facebook
Reply #5 - May 22nd, 2010, 7:30am
 
Chrisir wrote on May 22nd, 2010, 6:05am:
How can I download JSONObject.java
How do I make it part of my program Is it a library

You know, on the page JohnG pointed to The blue underlined texts are links. If you right-click on the JSONObject.java one, your browser should show a context menu item looking like "Download the target of this link". Once downloaded, you should have a Java file you can drop in your sketch's folder. Reopening your sketch, the file should appear in the tabs, and then you can use it.

If I find time, in a few hours (gotta go...) I will myself do that and try to use it, as it interests me too...
Re: get data from the web - Facebook
Reply #6 - May 22nd, 2010, 11:03am
 
Hello,

It's very complicated:

  • I am not sure if Facebook allows getting data from an app (instead of from another webpage)
    I am not sure if you have to register with Facebook first
    JSONObject.java produces errors, can't run
    it's loadStrings (instead if loadString)
    Maybe processing doesn't allow getting text


I also tried to get my picture from Facebook:

Code:
  myImage1 = loadImage ("https://graph.facebook.com/ChristophRoemhild/picture","jpg" );

size (600,600) ;
image(myImage1, 0, 0);


link works in the browser but not in processing...   Sad

Greetings, Chris  Wink
Re: get data from the web - Facebook
Reply #7 - May 22nd, 2010, 12:04pm
 
Chrisir wrote on May 22nd, 2010, 11:03am:
I am not sure if Facebook allows getting data from an app (instead of from another webpage)
I am not sure if you have to register with Facebook first

Actually, if you use the API of a site (at least large ones like Facebook, Twitter, etc.), you have to request a developer's key, which must be provided when connecting to the service.
And sometime (often) you are limited in the amount of requests/traffic.
Page Index Toggle Pages: 1