Photo from webcam upload to twitter keeps posting same photo rather than new

edited January 2017 in Arduino
import twitter4j.conf.*;
import twitter4j.*;
import twitter4j.auth.*;
import twitter4j.api.*;
import java.util.*;
import processing.video.*;
import processing.serial.*;

int picCount = 0;
Capture webcam;
Twitter twitter;

Serial myPort;    // The serial port
String inString;  // Input string from serial port
int lf = 10;      // ASCII linefeed

void setup() {
  size(640, 480);
  webcam = new Capture(this, 640, 480);  
  String[] devices = Capture.list();
  println(devices);
  webcam.start();

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

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

  twitter = tf.getInstance();

  myPort = new Serial(this, Serial.list()[0], 9600);
  myPort.bufferUntil(lf); 
}

void draw() {
  if (webcam.available() == true) {
    webcam.read();
    image(webcam, 0, 0);
  }

  if (inString != null) {
    inString = inString.trim();
    int val = int(inString);

    if (val == 1) {
      println("saving...");
      save("cam" + picCount + ".png");
      picCount++;

      //send tweet
      File file = new File("C:\\Users\\Jake\\Documents\\Processing\\Twitter test 2\\Twittertest2\\cam" + picCount + ".png");

      delay (3000);
      tweetPic(file, "");
    }
  }
}

void testPassingFile(File _file) {
  println(_file.exists());
  println(_file.getName());
  println(_file.getPath());
  println(_file.canRead());
}

void tweetPic(File _file, String theTweet) {
  try
  {
    StatusUpdate status = new StatusUpdate(theTweet);
    status.setMedia(_file);
    twitter.updateStatus(status);
  }
  catch (TwitterException te)
  {
    println("Error: "+ te.getMessage());
  }
}

void serialEvent(Serial p) {
  inString = p.readString();
}

Answers

  • Select code, press Ctrl-o to format code.

    Posting oauth secrets to public forums is probably not a good idea.

Sign In or Register to comment.