twitter4j image upload
in
Contributed Library Questions
•
1 year ago
Dear friends, how can I upload an image using the twitter4j library?
I already have this code running ok for posting text, using twitter4j 2.1.4 and Processing 2.0 alpha 8.
- import twitter4j.conf.*;
- import twitter4j.internal.async.*;
- import twitter4j.internal.org.json.*;
- import twitter4j.internal.logging.*;
- import twitter4j.http.*;
- import twitter4j.api.*;
- import twitter4j.util.*;
- import twitter4j.internal.http.*;
- import twitter4j.*;
- String msg = "Automatically posted from Processing";
- String consumer_key = "my key";
- String consumer_secret = "my secret";
- String oauth_token = "my token";
- String oauth_token_secret = "my token secret";
- color bgcolor = color(255);
- long timer;
- void setup() {
- size(640,480);
- }
- void draw() {
- background(bgcolor);
- if (millis()-timer > 2000) bgcolor = color(255);
- }
- void mousePressed() {
- Twitter twitter = new TwitterFactory().getOAuthAuthorizedInstance (
- consumer_key, consumer_secret,
- new AccessToken( oauth_token, oauth_token_secret) );
- try {
- Status st = twitter.updateStatus(msg + " " + second());
- println("Successfully updated the status to [" + st.getText() + "].");
- bgcolor = color(0,0,255);
- timer = millis();
- }
- catch (TwitterException e) {
- println(e.getStatusCode());
- }
- }
1