So führen Sie Processing + Twitter4j sketch in broswer @ a

Ich bin ein Anfänger in der Programmierpraxis und habe kürzlich eine Skizze entwickelt, die Twitter4j verwendet. Wenn ich die Skizze im Java-Modus in der Entwicklungsumgebung für die Verarbeitung ausführe, funktioniert sie einwandfrei. Auch wenn ich die Skizze aus dem Java-Modus exportiere, läuft die resultierende Anwendung perfekt. Wenn ich jedoch in den JavaScript-Modus wechsle und versuche, die Skizze auszuführen, wird in der Browservorschau nichts angezeigt.

Ich glaube, das Problem hängt mit Twitter4j zusammen, denn wenn ich den mit Twitter4j zusammenhängenden Code aus der Skizze entferne und ihn ausführe (im JavaScript-Modus), zeigt die Browservorschau die Verarbeitungs-Visualisierungen an.

Ich habe jetzt mehrere Stunden lang über mehrere Tage nach einer Lösung dafür gesucht, aber ich kann keine angemessene Antwort finden. Ich bin auf Beiträge gestoßen, die sich mit verwandten Themen befassten, aber die Antworten enthielten nur Begriffe wie "Signieren der JAR-Datei" (meiner Meinung nach nur im Java-Modus) oder haben nur Aufschluss über Probleme beim Ausführen von Verarbeitungsskizzen im JavaScript-Modus im Browser gegeben -ohn Skizzen, die die Verwendung von Twitter4j beinhalten.

Ich habe unten eine Kopie meines gesamten Codes eingefügt und würde mich sehr über eine schrittweise Antwort freuen, die sich an einen Neuling richtet. Ich suche nach einer Erklärung, wie ich meine im JavaScript-Modus exportierte Processing + Twitter4j-Skizze nach Möglichkeit in HTML / auf meiner Website ausführen kann.

ielen Dank für Ihre Zeit und Ihre Fähigkeiten. Ich habe einige Anmerkungen zum Code am Ende dieses Beitrags hinzugefügt.

import twitter4j.conf.*;
import twitter4j.*;
import twitter4j.auth.*;
import twitter4j.api.*;
import java.util.*;

Twitter twitter;
String searchString = "#brokendreams";
List<Status> tweets;
int currentTweet;
PFont f;

int amount1 = 300;
Star[] meteors = new Star[45];
StarDust[] sprinkle = {};
String chatter;

void setup() {
  size(800,600);
  f = createFont("Tahoma", 13, true);
  textFont(f, 13);

  ConfigurationBuilder cb = new ConfigurationBuilder();
  cb.setOAuthConsumerKey("---");
  cb.setOAuthConsumerSecret("---");
  cb.setOAuthAccessToken("---");
  cb.setOAuthAccessTokenSecret("---");

  TwitterFactory tf = new TwitterFactory(cb.build());

  twitter = tf.getInstance();

  getNewTweets();

  currentTweet = 0;

  dustField();

  Status status = tweets.get(currentTweet);

  for (int j = 0; j < meteors.length; j++) {
    meteors[j] = new Star(chatterText());
  }

}

void draw() {
  background(0, 35, 0);
  for (int i = 0; i < sprinkle.length; i++) {
    StarDust dust = sprinkle[i];
    dust.move();
  }

  for (int j = 0; j < meteors.length; j++) {
    meteors[j].appear();
    meteors[j].randomOrbit();
  }

  chatterText();

}

void dustField() {
  for (int i = 0; i < amount1; i++) {
    StarDust dust = new StarDust();
    dust.swish();
    sprinkle = (StarDust[])append(sprinkle, dust);
  }
}

String chatterText() {
  currentTweet += 1;
  if (currentTweet >= tweets.size()) {
    currentTweet = 0;
  }
  Status status = tweets.get(currentTweet);
  chatter = status.getText();
  return chatter;
}

void getNewTweets() {
    try {
      Query query = new Query(searchString);
      QueryResult result = twitter.search(query);
      tweets = result.getTweets();
    } catch (TwitterException te) {
      System.out.println("Failed to search tweets: " + te.getMessage());
      System.exit(-1);
    } 
}

void refreshTweets() {
  while (true) {
    getNewTweets();
    println("Updated Tweets"); 
    delay(30000);
  }
}
class Star {

  float x, y;
  float xmove, ymove;
  float radius;
  color linecol, fillcol;
  float alpha;
  String msg;
  float frag1, frag2, frag3, frag4;

  Status status;

  Star(String message) {

    msg = message;
    x = random(width);
    y = random(height);
    radius = random(20, 60) + 10;
    linecol = color(random(255), random(255), random(255));
    fillcol = color(random(255), random(255), random(255));
    alpha = random(200);
    xmove = sin(random(2) / 2);
    ymove = sin(random(2) / 2);
    frag1 = random(radius/5);
    frag2 = random(radius/3);
    frag3 = random(radius/4);
    frag4 = random(radius/2);

  }

  void appear() {

    if (mouseX > x-(radius/2) && mouseX < x+(radius/2) && mouseY > y-(radius/2) && mouseY < y+(radius/2)) {

      strokeWeight(1);
      stroke(linecol);
      noFill();
      ellipse(x, y, radius, radius);

    } else {

      noStroke();
      fill(fillcol, alpha);
      ellipse(x, y, radius, radius);

    }

    fill(fillcol);
    noStroke();
    beginShape();
    vertex(x - (radius/3), y + frag1 - frag2);
    vertex(x, y - (radius/3));
    vertex(x, y);
    endShape(CLOSE);

    fill(linecol, alpha);
    beginShape();
    vertex(x, y);
    vertex(x, y - (radius/3));
    vertex(x + (radius/4), y - frag3 - frag4);
    vertex(x + (radius/3), y + frag1 - frag2);
    endShape(CLOSE);

    fill(fillcol);
    beginShape();
    vertex(x, y);
    vertex(x + (radius/3), y + frag1 - frag2);
    vertex(x + (radius/4), y + frag3);
    endShape(CLOSE);

    fill(linecol, alpha);
    beginShape();
    vertex(x, y);
    vertex(x + (radius/4), y + frag3);
    vertex(x + (radius/5), y + frag2);
    vertex(x, y + (radius/3));
    vertex(x - (radius/3), y + frag1 - frag2);
    endShape(CLOSE);

  }

  void randomOrbit() {

    x += xmove;
    y += ymove;
    if (x > (width + radius)) { x = 0 - radius; }
    if (x < (0 - radius)) { x = width + radius; }
    if (y > (height + radius)) { y = 0 - radius; }
    if (y < (0 - radius)) { y = height + radius; }
    appear();
    displayTweet();

  }

  void displayTweet() {

    if (mouseX > x-(radius/2) && mouseX < x+(radius/2) && mouseY > y-(radius/2) && mouseY < y+(radius/2) && mousePressed) {
      x = mouseX;
      y = mouseY;
      fill(255);
      text(msg, mouseX + 30, mouseY, 200, 200);
      mouseReleased();

    }

  }

  void mouseReleased() {alpha = 80;}

}
class StarDust {

  float x, y;
  float xmove, ymove;
  float radius;
  float alpha, beta;

  Status status;

  StarDust() {
    x = random(width);
    y = random(height);
    radius = random(2, 4);
    alpha = random(255);
    beta = random(155);
    xmove = random(1.9) - 0.9;
    ymove = random(1.9) - 0.9;

  }

  void flipColor() {

      fill(random(255), random(255), random(255), beta);
      stroke(random(255), random(255), random(255), beta);

  }

  void swish() {

    flipColor();
    rect(x, y, radius, radius);

  }

  void move() {

    swish();
    x += xmove;
    y += ymove;
    if (x > (width + radius)) { x = 0 - radius; }
    if (x < (0 - radius)) { x = width + radius; }
    if (y > (height + radius)) { y = 0 - radius; }
    if (y < (0 - radius)) { y = height + radius; }
    squarespray(xmove);

  }

  void squarespray(float spray) {
    stroke(random(175, 255), random(255), 0, alpha);
    strokeWeight(random(7));
    point(x + random(radius), y + random(spray));
    point(y + sin(spray) * radius, x - spray);
    point(random(spray) - 60 + y, random(radius) + x - 30);
  }

}

-Sorry habe ich nicht kommentiert. Das ist eine Angewohnheit, an der ich noch arbeite. Ich glaube jedoch nicht, dass irgendetwas nach den Hauptzeilen von Twitter4j relevant ist.

-Im obigen Code ist "---" ein Ersatz für meine Schlüssel.

-Dies ist der Code, der ansonsten genau so ist, wie ich ihn aus dem JavaScript-Modus exportiert habe und von meinem Browser ausführen möchte.

-Ich habe auf meiner Website bereits Verarbeitungsskizzen ausgeführt. Dies ist das erste Mal, dass Twitter4j involviert ist.

Antworten auf die Frage(2)

Ihre Antwort auf die Frage