Processing.js and the twitter API, impossible?

edited November 2013 in JavaScript Mode

Hello everybody,

I am currently working on a project where I want to load tweets from a user's timeline into a processing sketch.

I managed to do this with a contributed library called Twitter4J.

But now I want to show my sketch on a website but I learned that Processing.js does not support contributed libraries. There used to be some javascripts to do it but sadly twitter updated their API to a OAuth-based authentication system. Is there any way to do this OAuth stuff in combination with processing.js?

Thanks in Advance, Merijn

Answers

  • You will have to make AJAX calls in native Javascript to query the data. It is my understanding that ProcessingJS and Javscript can be mixed. You will have to export the sketch to ProcessingJS, then add the native Javascript code.

    There is a Jquery library for interacting with the Twitter REST API. Now may be a good time to learn how ProcessingJS and native Javascript can work together.

  • Answer ✓

    "You will have to make AJAX calls in native Javascript to query the data"
    This can be done with loadStrings(), for example, but it won't work: JS can make regular Ajax calls only to the server providing the script. To query a 3rd party server, you have to use tricks, like using JsonP if it allows it, or similar stuff.

  • edited November 2013

    I found the solution!

    Eventually I went with abraham's twitteroauth php library: github

    It's a great tool for accessing the twitter API because it's a lot easier to use than most js solutions for this. I just set up the php script to put the tweets into a javascript object array by using json_encode like this:

    PHP

    $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitteruser."&count=".$notweets);

    JS

    var twArray = <?php echo json_encode($tweets); ?> ;

    Once you have your js object array filled you can access it in processing like you would with any normal array within processing.

    It's also more secure than using js because all the authenticating is done server-side.

    Thanks anyway! Merijn

Sign In or Register to comment.