Example usage for twitter4j Twitter updateStatus

List of usage examples for twitter4j Twitter updateStatus

Introduction

In this page you can find the example usage for twitter4j Twitter updateStatus.

Prototype

Status updateStatus(String status) throws TwitterException;

Source Link

Document

Updates the authenticating user's status.

Usage

From source file:br.shura.team.mpsbot.venusext.Tweet.java

License:Open Source License

@Override
public IntegerValue call(Context context, FunctionCallDescriptor descriptor) throws ScriptRuntimeException {
    ConnectedBot bot = context.getApplicationContext().getUserData("bot", ConnectedBot.class);
    Twitter twitter = bot.getHandler();
    StringValue value = (StringValue) descriptor.get(0);
    Status status = Helper.execute(context, () -> twitter.updateStatus(value.value()));

    return status != null ? new IntegerValue(status.getId()) : new IntegerValue(0);
}

From source file:br.unisal.twitter.bean.TwitterBean.java

public void postingToTwitter() {
    try {/*w ww .  j a  va 2 s  . co m*/
        TwitterFactory TwitterFactory = new TwitterFactory();
        Twitter twitter = TwitterFactory.getSingleton();

        String message = getTwitt();
        Status status = twitter.updateStatus(message);

        /*String s = "status.toString() = " + status.toString()
         + "status.getInReplyToScreenName() = " + status.getInReplyToScreenName()
         + "status.getSource() = " + status.getSource()
         + "status.getText() = " + status.getText()
         + "status.getContributors() = " + Arrays.toString(status.getContributors())
         + "status.getCreatedAt() = " + status.getCreatedAt()
         + "status.getCurrentUserRetweetId() = " + status.getCurrentUserRetweetId()
         + "status.getGeoLocation() = " + status.getGeoLocation()
         + "status.getId() = " + status.getId()
         + "status.getInReplyToStatusId() = " + status.getInReplyToStatusId()
         + "status.getInReplyToUserId() = " + status.getInReplyToUserId()
         + "status.getPlace() = " + status.getPlace()
         + "status.getRetweetCount() = " + status.getRetweetCount()
         + "status.getRetweetedStatus() = " + status.getRetweetedStatus()
         + "status.getUser() = " + status.getUser()
         + "status.getAccessLevel() = " + status.getAccessLevel()
         + "status.getHashtagEntities() = " + Arrays.toString(status.getHashtagEntities())
         + "status.getMediaEntities() = " + Arrays.toString(status.getMediaEntities())
         + "status.getURLEntities() = " + Arrays.toString(status.getURLEntities())
         + "status.getUserMentionEntities() = " + Arrays.toString(status.getUserMentionEntities());*/
        String s = "status.getId() = " + status.getId() + "\nstatus.getUser() = " + status.getUser().getName()
                + " - " + status.getUser().getScreenName() + "\nstatus.getGeoLocation() = "
                + status.getGeoLocation() + "\nstatus.getText() = " + status.getText();
        setTwittsResult(s);
        this.getUiMsg().setSubmittedValue("");
        this.getUiResultMsg().setSubmittedValue(getTwittsResult());
    } catch (TwitterException ex) {
        LOG.error("Erro no postingToTwitter() - " + ex.toString());
    }
}

From source file:clientetwitter.ClienteTwitter.java

public static void PostInTimeLine(String texto) throws TwitterException {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("xxxxxxxxxxxx") //to get all the OAuth go to apps.twitter.com 
            .setOAuthConsumerSecret("xxxxxxxxxxxxxxxx").setOAuthAccessToken("xxxxxxxxxxxxxxxxxxxxxxx")
            .setOAuthAccessTokenSecret("xxxxxxxxxxxxxxxxxxxx");

    TwitterFactory tf = new TwitterFactory(cb.build());
    twitter4j.Twitter tw = tf.getInstance();

    //posting//w  w  w .  j av  a 2s. c o m
    Status stat = tw.updateStatus(texto);
    System.out.println("Posted");

}

From source file:com.ak.android.akplaza.common.sns.twitter.TwitterController.java

License:Open Source License

public static void write(String content, Activity at) {
    //      Log.d(TAG, "content : " + content);
    String path = Environment.getExternalStorageDirectory().getAbsolutePath();
    String fileName = "example.jpg";
    InputStream is = null;/*from www  .ja  va  2s . c  om*/

    try {
        if (new File(path + File.separator + fileName).exists())
            is = new FileInputStream(path + File.separator + fileName);
        else
            is = null;

        ConfigurationBuilder cb = new ConfigurationBuilder();
        String oAuthAccessToken = acToken.getToken();
        String oAuthAccessTokenSecret = tacs;
        String oAuthConsumerKey = C.TWITTER_CONSUMER_KEY;
        String oAuthConsumerSecret = C.TWITTER_CONSUMER_SECRET;
        cb.setOAuthAccessToken(oAuthAccessToken);
        cb.setOAuthAccessTokenSecret(oAuthAccessTokenSecret);
        cb.setOAuthConsumerKey(oAuthConsumerKey);
        cb.setOAuthConsumerSecret(oAuthConsumerSecret);
        Configuration config = cb.build();
        OAuthAuthorization auth = new OAuthAuthorization(config);

        TwitterFactory tFactory = new TwitterFactory(config);
        Twitter twitter = tFactory.getInstance();
        //         ImageUploadFactory iFactory = new ImageUploadFactory(getConfiguration(C.TWITPIC_API_KEY));
        //         ImageUpload upload = iFactory.getInstance(MediaProvider.TWITPIC, auth);

        if (is != null) {
            //        String strResult = upload.upload("example.jpg", is, mEtContent.getText().toString());
            //        twitter.updateStatus(mEtContent.getText().toString() + " " + strResult);
        } else
            twitter.updateStatus(content);
        new AlertDialog.Builder(at).setMessage(" ? ? ?.")
                .setPositiveButton("?", null).show();
    } catch (Exception e) {
        e.printStackTrace();
        new AlertDialog.Builder(at).setMessage("? ?  ")
                .setPositiveButton("?", null).show();
    } finally {
        try {
            is.close();
        } catch (Exception e) {
        }
    }

}

From source file:com.alta189.cyborg.commandkit.twitter.TwitterCommands.java

License:Open Source License

@Command(name = "tweet", desc = "Updates your twitter status")
@Usage(".tweet <status>...")
public CommandResult tweet(CommandSource source, CommandContext context) {
    if (source.getSource() != CommandSource.Source.USER) {
        return get(ReturnType.MESSAGE, "Muse be done from IRC.", source, context);
    }/*from   w  w w .  j  a  v a2 s .  c  om*/

    if (context.getPrefix() == null || !context.getPrefix().equals(".")) {
        return null;
    }

    if (context.getArgs() == null || context.getArgs().length < 1) {
        return get(ReturnType.MESSAGE, "Correct usage is .tweet <status>", source, context);
    }

    CyborgUser permsAccount = getUser(source.getUser());

    if (getUser(source.getUser()) == null) {
        return get(ReturnType.NOTICE,
                "You have not registered with me! You need to register to use a twitter account! Type .register for help!",
                source, context);
    }

    TwitterUser twitterUser = getDatabase().select(TwitterUser.class).where()
            .equal("permUser", permsAccount.getName()).execute().findOne();
    if (twitterUser == null) {
        return get(ReturnType.NOTICE,
                "You don't have a twitter user associated with your account! Try .twituser <twitter user>",
                source, context);
    }

    String status = StringUtils.toString(context.getArgs());

    Twitter twitter = defaultTwitterFactory.getInstance();
    twitter.setOAuthAccessToken(twitterUser.getAccessTokenObject());

    try {
        twitter.updateStatus(status);
        return get(ReturnType.MESSAGE, "Updated status!", source, context);
    } catch (TwitterException e) {
        e.printStackTrace();
        return get(ReturnType.MESSAGE, "Internal Twitter Exception http code:" + e.getStatusCode(), source,
                context);
    }
}

From source file:com.amandine.twitterpostforcoucou.Tweet.java

private void publishStatusUpdateWithMedia(String message) throws MalformedURLException, IOException {
    Status status = null;// w  w  w  .  j  av  a  2s . c o  m
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        try {
            RequestToken requestToken = twitter.getOAuthRequestToken();
            AccessToken accessToken = null;
            while (null == accessToken) {
                logger.fine("Open the following URL and grant access to your account:");
                logger.fine(requestToken.getAuthorizationURL());
                try {
                    accessToken = twitter.getOAuthAccessToken(requestToken);
                } catch (TwitterException te) {
                    if (401 == te.getStatusCode()) {
                        logger.severe("Unable to get the access token.");
                    } else {
                        te.printStackTrace();
                    }
                }
            }
            logger.log(Level.INFO, "Got access token.");
            logger.log(Level.INFO, "Access token: {0}", accessToken.getToken());
            logger.log(Level.INFO, "Access token secret: {0}", accessToken.getTokenSecret());
        } catch (IllegalStateException ie) {
            // access token is already available, or consumer key/secret is not set.
            if (!twitter.getAuthorization().isEnabled()) {
                logger.severe("OAuth consumer key/secret is not set.");
                return;
            }
        }
        //Instantiate and initialize a new twitter status update
        StatusUpdate statusUpdate = new StatusUpdate(message);
        //attach any media, if you want to
        statusUpdate.setMedia(
                //title of media
                "Amandine Leforestier Spring Summer 2015 white",
                new URL("https://issuu.com/kadiemurphy/docs/volume_xxi_issuu/52?e=0").openStream());
        //tweet or update status
        status = twitter.updateStatus(statusUpdate);

        //Status status = twitter.updateStatus(message);
        logger.log(Level.INFO, "Successfully updated the status to [{0}].", status.getText());
    } catch (TwitterException te) {
        te.printStackTrace();
        logger.log(Level.SEVERE, "Failed to get timeline: {0}", te.getMessage());
    }
}

From source file:com.amandine.twitterpostforcoucou.Tweet.java

public void tweetMessageToUser(String username, String hashtags, String imageUrl, String targetUrl,
        String twitterid) {//from w w  w .jav  a 2 s. c  om
    Twitter twitterHandle = this.getTwitter();
    //Instantiate and initialize a new twitter status update
    String message = username + " " + targetUrl + " " + hashtags + " #amandineleforestier";
    StatusUpdate statusUpdate = new StatusUpdate(message);
    try {
        //attach any media, if you want to
        statusUpdate.setMedia(//title of media
                "Amandine Leforestier Athleasure Sport-Chic Autumn Winter 2015 http://shop.amandineleforestier.fr",
                new URL(imageUrl).openStream());
    } catch (MalformedURLException ex) {
        logger.log(Level.SEVERE, "Bad image Url {0}", ex.getMessage());
    } catch (IOException ex) {
        logger.log(Level.SEVERE, "Cannot open Url {0}", ex.getMessage());
    }
    //tweet or update status
    Status status = null;
    try {
        status = twitterHandle.updateStatus(statusUpdate);
        logTheStatusUpdate(twitterid, message, imageUrl, targetUrl);
    } catch (TwitterException te) {
        logger.log(Level.SEVERE, "Failed to get timeline: {0}", te.getMessage());
    }
    //Status status = twitter.updateStatus(message);
    if (status != null) {
        logger.log(Level.INFO, "Successfully updated the status to [{0}].", status.getText());
    } else {
        logger.log(Level.SEVERE, "Status update failed [{0}].", status);
    }
}

From source file:com.appspot.bitlyminous.handler.twitter.TweetForMeHandler.java

License:Apache License

@Override
public StatusUpdate execute(Status tweet) {
    try {//  w  ww. ja v a  2  s  .  co  m
        User user = context.getUser();
        if (user == null) {
            user = getUserByScreenName(tweet.getUser().getScreenName());
            context.setUser(user);
        }
        if (user == null || user.getTwitterToken() == null || user.getTwitterSecret() == null) {
            StatusUpdate reply = new StatusUpdate(
                    ApplicationResources.getLocalizedString("com.appspot.bitlyminous.message.notAuthenticated",
                            new String[] { "@" + tweet.getUser().getScreenName(), "Twitter",
                                    shortenUrl(ApplicationConstants.TWITTER_CALLBACK_URL) }));
            reply.setInReplyToStatusId(tweet.getId());
            return reply;
        } else {
            Twitter twitter = getTwitterClient(user.getTwitterToken().getValue(),
                    user.getTwitterSecret().getValue());
            String status = buildStatus(user.getUrls(), user.getTags());
            if (status != null) {
                StatusUpdate reply = new StatusUpdate(status);
                reply.setInReplyToStatusId(tweet.getId());
                twitter.updateStatus(reply);
            }
            return null;
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Error while tweeting on behalf of user.", e);
    }
    return null;
}

From source file:com.appspot.bitlyminous.service.impl.TwitterServiceImpl.java

License:Apache License

public void handleMentions() {
    try {/*w w  w. j  a  v  a  2  s  . c  om*/
        Twitter twitter = getTwitterClient();
        TwitterHandlerFactory factory = TwitterHandlerFactory.newInstance(new TwitterContext());
        Version version = getCurrentVersion();
        ResponseList<Status> homeTimeline = twitter
                .getMentions(new Paging(getCurrentVersion().getLastMentionId()));
        long lastMentionId = 0L;
        for (Status tweet : homeTimeline) {
            if (tweet.getId() > version.getLastMentionId()) {
                if (tweet.getId() > lastMentionId) {
                    lastMentionId = tweet.getId();
                }
                TwitterHandler command = factory.createCommand(tweet);
                StatusUpdate reply = command.execute(tweet);
                if (reply != null) {
                    twitter.updateStatus(reply);
                }
            }
        }
        if (lastMentionId > version.getLastMentionId()) {
            version.setLastMentionId(lastMentionId);
            EntityManager entityManager = createEntityManager();
            entityManager.persist(version);
            closeEntityManager(entityManager);
        }
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}

From source file:com.appspot.bitlyminous.service.impl.TwitterServiceImpl.java

License:Apache License

public void handleFriendsTimeline() {
    try {//from  w  ww . j a v a2s  .  c om
        Version version = getCurrentVersion();
        Twitter twitter = getTwitterClient();
        List<Status> homeTimeline = twitter.getFriendsTimeline(new Paging(version.getLastHomeTweetId()));
        long lastTweetId = 0L;
        for (Status status : homeTimeline) {
            if (status.getId() > lastTweetId) {
                lastTweetId = status.getId();
            }
            if (!ApplicationConstants.TWITTER_SCREEN_NAME.equalsIgnoreCase(status.getUser().getScreenName())) {
                TwitterContext context = new TwitterContext();
                context.setVersion(version);
                for (TwitterHandler command : getTimelineHandlers(context)) {
                    StatusUpdate reply = command.execute(status);
                    if (reply != null) {
                        twitter.updateStatus(reply);
                    }
                }
                saveUser(context.getUser());
            }
        }
        if (lastTweetId > version.getLastHomeTweetId()) {
            version.setLastHomeTweetId(lastTweetId);
            saveVersion(version);
        }
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}