Twitter4J and XML "the type XML is ambiguous"
in
Contributed Library Questions
•
5 months ago
Hi
Does anyone have advice for how to use twitter 4J and access the XML core functionality in the same sketch?
I'm using processing 2.0b8 and I have the small block of code below working in a separate sketch that pulls in and parses a BBC xml weather feed but as soon as I add these lines to a sketch that also pulls in searches twitters API for images I get a "The type XML is ambiguous" error. The twitter sketch is based on this one
https://github.com/neufuture/SimpleTwitterStream/ and anywhere I put the XML block below it makes the type ambiguous.
- XML feed = loadXML("http://open.live.bbc.co.uk/weather/feeds/en/2644210/observations.rss");
- String obs = feed.getChild("channel/item/description").getContent();
- String when = feed.getChild("channel/item/pubDate").getContent();
- String[] da= match(obs, "Temperature: ([\\d]*)°C \\([\\d]*°F\\), Wind Direction: ([\\w ]*), Wind Speed: ([\\d]*)mph, Humidity: ([\\d]*)%, Pressure: ([\\d]*mb, [\\w ]*)");
- print(" ");
- println(da[0]);
Modified twitter image search with Oauth credentials below: Also has some twitter 4j files in the code folder of the sketch - as per the github example link above.
- /*
- SimpleTwitterStreaming
- Developed by: Michael Zick Doherty
- 2011-10-18
- http://neufuture.com
- */
- ///////////////////////////// Config your setup here! ////////////////////////////
- // This is where you enter your Oauth info
- static String OAuthConsumerKey = "";
- static String OAuthConsumerSecret = "";
- // This is where you enter your Access Token info
- static String AccessToken = "";
- static String AccessTokenSecret = "";
- // if you enter keywords here it will filter, otherwise it will sample
- String keywords[] = {"hello"
- };
- ///////////////////////////// End Variable Config ////////////////////////////
- TwitterStream twitter = new TwitterStreamFactory().getInstance();
- PImage img;
- boolean imageLoaded;
- void setup() {
- size(800, 600);
- noStroke();
- imageMode(CENTER);
- connectTwitter();
- twitter.addListener(listener);
- if (keywords.length==0) twitter.sample();
- else twitter.filter(new FilterQuery().track(keywords));
- }
- void draw() {
- background(0);
- if (imageLoaded) image(img, width/2, height/2);
- XML feed = loadXML("http://open.live.bbc.co.uk/weather/feeds/en/2644210/observations.rss");
- String obs = feed.getChild("channel/item/description").getContent();
- String[] da= match(obs, "Temperature: ([\\d]*)°C \\([\\d]*°F\\), Wind Direction: ([\\w ]*), Wind Speed: ([\\d]*)mph, Humidity: ([\\d]*)%, Pressure: ([\\d]*mb, [\\w ]*)");
- println(da[0]);
- }
- // Initial connection
- void connectTwitter() {
- twitter.setOAuthConsumer(OAuthConsumerKey, OAuthConsumerSecret);
- AccessToken accessToken = loadAccessToken();
- twitter.setOAuthAccessToken(accessToken);
- }
- // Loading up the access token
- private static AccessToken loadAccessToken() {
- return new AccessToken(AccessToken, AccessTokenSecret);
- }
- // This listens for new tweet
- StatusListener listener = new StatusListener() {
- public void onStatus(Status status) {
- //println("@" + status.getUser().getScreenName() + " - " + status.getText());
- String imgUrl = null;
- String imgPage = null;
- // Checks for images posted using twitter API
- if (status.getMediaEntities() != null) {
- imgUrl= status.getMediaEntities()[0].getMediaURL().toString();
- }
- // Checks for images posted using other APIs
- else {
- if (status.getURLEntities().length > 0) {
- if (status.getURLEntities()[0].getExpandedURL() != null) {
- imgPage = status.getURLEntities()[0].getExpandedURL().toString();
- }
- else {
- if (status.getURLEntities()[0].getDisplayURL() != null) {
- imgPage = status.getURLEntities()[0].getDisplayURL().toString();
- }
- }
- }
- // if (imgPage != null) imgUrl = parseTwitterImg(imgPage);
- }
- if (imgUrl != null) {
- println("found image: " + imgUrl);
- // hacks to make image load correctly
- if (imgUrl.startsWith("//")){
- println("s3 weirdness");
- imgUrl = "http:" + imgUrl;
- }
- if (!imgUrl.endsWith(".jpg")) {
- byte[] imgBytes = loadBytes(imgUrl);
- saveBytes("tempImage.jpg", imgBytes);
- imgUrl = "tempImage.jpg";
- }
- println("loading " + imgUrl);
- img = loadImage(imgUrl);
- imageLoaded = true;
- }
- }
- public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
- //System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
- }
- public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
- // System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
- }
- public void onScrubGeo(long userId, long upToStatusId) {
- System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
- }
- public void onException(Exception ex) {
- ex.printStackTrace();
- }
- };
1