Example usage for twitter4j StatusUpdate StatusUpdate

List of usage examples for twitter4j StatusUpdate StatusUpdate

Introduction

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

Prototype

public StatusUpdate(String status) 

Source Link

Usage

From source file:com.twitstreet.twitter.AnnouncerMgrImpl.java

License:Open Source License

@Override
public void reply(String message, long statusId) {
    Twitter twitter = random();/*from   w  ww  .j  a v a  2s . com*/
    String screenName = "";
    if (twitter != null) {
        try {
            twitter.updateStatus(new StatusUpdate(message).inReplyToStatusId(statusId));
            screenName = twitter.getScreenName();
        } catch (TwitterException e) {
            logger.error("Announcement failed: " + screenName, e);
        }
    } else {
        logger.error("TwitStreet announcer is null");
    }
}

From source file:com.twitstreet.twitter.AnnouncerMgrImpl.java

License:Open Source License

@Override
public void replyForDiabloBird(String message, long statusId) {
    Twitter twitter = diablobird;//w w  w .  j a v a2 s.co m
    String screenName = "";
    if (twitter != null) {
        try {
            twitter.updateStatus(new StatusUpdate(message).inReplyToStatusId(statusId));
            screenName = twitter.getScreenName();
            logger.info("replyForDiabloBird");
        } catch (TwitterException e) {
            logger.error("Announcement failed: " + screenName, e);
        }
    } else {
        logger.error("TwitStreet announcer is null");
    }
}

From source file:com.twitter.tokyo.kucho.daemon.KuchoController.java

License:Apache License

@Override
public void onStatus(Status status) {
    String screenName = status.getUser().getScreenName();
    // lookup modules for the user's seat
    List<String> modules = seatingList.getVentilationModules(status.getUser().getScreenName());
    if (modules.size() == 0) {
        // user is not in the list. do nothing
        return;/*w  w w .j  a v a2s. c o m*/
    }

    String text = status.getText().toLowerCase().replaceAll("", "#");
    // does the tweet contain room name?
    for (String roomName : seatingList.getRooms()) {
        if (text.contains(roomName)) {
            modules = seatingList.getVentilationModulesIn(roomName);
            break;
        }
    }

    int degree = 2;
    if (text.matches(
            ".*(???|????|??|??|??|???|???|?|max|||???|?|?|????|??|?|"
                    + "|???|?|?||??|??|???|????|???|???|??|?|??"
                    + "|too|very|extremely|intensively).*")) {
        degree = 4;
    }
    for (String hot : HOT) {
        if (text.contains(hot)) {
            degree = degree * -1;
            break;
        }
    }

    String message = null;
    String imagePath = null;
    String powerfully = Math.abs(degree) == 4 ? "????" : "";
    if (degree < 0) {
        if (ehills.adjust(degree, modules)) {
            message = "@" + screenName + " " + powerfully + "?????? " + Message.getMessage();
            imagePath = "/atsui.jpg";
        } else {
            message = "@" + screenName + " ???????????";
            imagePath = "/kucho.jpg";
        }
    } else {
        if (ehills.adjust(degree, modules)) {
            message = "@" + screenName + "  " + powerfully + "?????? " + Message.getMessage();
            imagePath = "/samui.jpg";
        } else {
            message = "@" + screenName + " ??????????????";
            imagePath = "/kucho.jpg";
        }
    }
    System.out.println("messaage:" + message + " " + imagePath);
    try {
        if (!dryRun) {
            imagePath = "src/main/resources" + imagePath;
            if (!new File(".").getAbsolutePath().contains("kucho-daemon")) {
                imagePath = "kucho-daemon/" + imagePath;
            }
            File imageFile = new File(imagePath);
            if (imageFile.exists()) {
                TwitterFactory.getSingleton().updateStatus(
                        new StatusUpdate(message).media(imageFile).inReplyToStatusId(status.getId()));
            } else {
                TwitterFactory.getSingleton()
                        .updateStatus(new StatusUpdate(message).inReplyToStatusId(status.getId()));
            }
        }
    } catch (TwitterException e) {
        logger.error("failed to update status", e);
    }
}

From source file:com.vti.managers.TwitterManager.java

License:Apache License

/**
 * publish status to account vti_robot on twitter
 * //  www.ja  v  a  2s. c o m
 * @param tweet
 */
public void tweet(final String tweet, GeoLocation loc) {
    try {
        StatusUpdate status = new StatusUpdate(tweet);
        status.setLocation(loc);
        twitter.updateStatus(status);
    } catch (TwitterException e) {
        Log.d(TAG, Log.stack2string(e));
    }
}

From source file:com.yfiton.notifiers.twitter.TwitterNotifier.java

License:Apache License

@Override
protected void notify(Parameters parameters) throws NotificationException {
    try {/* w  w w.j  ava  2s .  co m*/
        StatusUpdate statusUpdate = new StatusUpdate(status);
        Status status = twitter.updateStatus(statusUpdate);

        log.info("https://twitter.com/" + status.getUser().getScreenName() + "/status/" + status.getId());
    } catch (TwitterException e) {
        throw new NotificationException(new String[] { e.getErrorMessage(),
                "Error code " + e.getErrorCode() + ": https://dev.twitter.com/overview/api/response-codes" },
                e);
    }
}

From source file:Controller.DetailsmesoffresController.java

@FXML
void partageTwitter(ActionEvent event) throws TwitterException, FileNotFoundException {

    OffreService offreService = new OffreService();
    FXMLAfficheroffresController z = new FXMLAfficheroffresController();

    Offre x = offreService.findById(Integer.parseInt(FXMLAfficheroffresController.getLabelid()));

    ConfigurationBuilder cb = new ConfigurationBuilder();

    cb.setDebugEnabled(true).setOAuthConsumerKey("zFrvXiT4O6bPh7wtfX2qpxTJM")
            .setOAuthConsumerSecret("pZeG2yJ71HYSu3y8MC4sbOcAeKstRKmp8bVKfCOmxnd4QjsKmC")
            .setOAuthAccessToken("3345656831-F533Ns9kdMPI6GfmHwiVor3BUHM6kYJn4WO4xhq")
            .setOAuthAccessTokenSecret("1hWrntZlel0gOju0xOEVf2t5kRo2CjSp5H75sieOUfT89");

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

    twitter4j.Twitter tw = tf.getInstance();

    String pathphoto = x.getPhoto();
    String nomphoto = pathphoto.substring(62);
    System.out.println(nomphoto);

    File file = null;/*from w ww .java  2  s . c  om*/
    file = new File(x.getPhoto());

    String StatusMessage = (x.getPtvente().getNom() + "\n" + x.getDescription() + "\n" + x.getTaux_remise());

    StatusUpdate status = new StatusUpdate(StatusMessage);
    status.setMedia(file);
    tw.updateStatus(status);

}

From source file:Controller.DetailsOffreController.java

@FXML
void partagersurtwitter(ActionEvent event) throws TwitterException {

    OffreService offreService = new OffreService();
    AfficherToutesOffresController z = new AfficherToutesOffresController();

    Offre x = offreService.findById(Integer.parseInt(AfficherToutesOffresController.getLabelid()));

    ConfigurationBuilder cb = new ConfigurationBuilder();

    cb.setDebugEnabled(true).setOAuthConsumerKey("zFrvXiT4O6bPh7wtfX2qpxTJM")
            .setOAuthConsumerSecret("pZeG2yJ71HYSu3y8MC4sbOcAeKstRKmp8bVKfCOmxnd4QjsKmC")
            .setOAuthAccessToken("3345656831-F533Ns9kdMPI6GfmHwiVor3BUHM6kYJn4WO4xhq")
            .setOAuthAccessTokenSecret("1hWrntZlel0gOju0xOEVf2t5kRo2CjSp5H75sieOUfT89");

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

    twitter4j.Twitter tw = tf.getInstance();

    String pathphoto = x.getPhoto();
    String nomphoto = pathphoto.substring(62);
    System.out.println(nomphoto);

    File file = null;//from  www  .j av a  2s  .  c om
    file = new File(x.getPhoto());

    String StatusMessage = (x.getPtvente().getNom() + "\n" + x.getDescription() + "\n" + x.getTaux_remise());

    StatusUpdate status = new StatusUpdate(StatusMessage);
    status.setMedia(file);
    tw.updateStatus(status);

}

From source file:cz.mgn.collabdesktop.utils.apis.twitter.CollabTwitter.java

License:Open Source License

public static void tweet(String roomName, String text, BufferedImage roomImage, String accessToken,
        String accessTokenSecret) {
    try {/*from  www . ja  va  2  s.c om*/
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true) //
                .setOAuthConsumerKey("PLFCUaLARG3rW66MbME1Kg") // twitter app: MG Collab desktop
                .setOAuthConsumerSecret("Rf5G5htymWOVnC4KGT5lSzaAzlgW6mUwXNIPnywI8") //
                .setOAuthAccessToken(accessToken) //
                .setOAuthAccessTokenSecret(accessTokenSecret);
        Twitter twitter = new TwitterFactory(cb.build()).getInstance();
        StatusUpdate su = new StatusUpdate(text);
        su.media(roomName, makeInputStreamFromImage(roomImage));
        twitter.updateStatus(su);
    } catch (IOException ex) {
        Logger.getLogger(CollabTwitter.class.getName()).log(Level.SEVERE, null, ex);
    } catch (TwitterException ex) {
        Logger.getLogger(CollabTwitter.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:de.hoesel.dav.buv.twitter.baustelle.BaustelleTwitternDialog.java

License:Open Source License

@Override
protected void okPressed() {
    RahmenwerkService service = RahmenwerkService.getService();
    Twitter twitter = service.getTwitter();

    try {//from   w  w w  . j a v a  2  s.  co  m
        // TODO:Bilder funktionieren noch nicht richtig
        // InputStream resourceAsStream =
        // BaustelleTwitternDialog.class.getResourceAsStream("baustelle.gif");
        StatusUpdate update = new StatusUpdate("[Test] " + messgae.getText());

        if (location != null) {
            // TODO: Das funktioniert nur, wenn man in seinen Twitter
            // Setting via Opt-In das Anzeigen der Location erlaubt.
            update.displayCoordinates(true);
            update.setLocation(location);
        }
        // update.setMedia("Baustelle",resourceAsStream);

        twitter.updateStatus(update);
        super.okPressed();
    } catch (TwitterException e) {
        setErrorMessage(e.getLocalizedMessage());
        e.printStackTrace();
    }

}

From source file:de.vanita5.twittnuker.service.BackgroundOperationService.java

License:Open Source License

private List<SingleResponse<ParcelableStatus>> updateStatus(final Builder builder,
        final ParcelableStatusUpdate statusUpdate) {
    final ArrayList<ContentValues> hashtag_values = new ArrayList<ContentValues>();
    final Collection<String> hashtags = extractor.extractHashtags(statusUpdate.text);
    for (final String hashtag : hashtags) {
        final ContentValues values = new ContentValues();
        values.put(CachedHashtags.NAME, hashtag);
        hashtag_values.add(values);/*  w  ww.  ja  va  2 s.  c o m*/
    }
    boolean notReplyToOther = false;
    mResolver.bulkInsert(CachedHashtags.CONTENT_URI,
            hashtag_values.toArray(new ContentValues[hashtag_values.size()]));

    final List<SingleResponse<ParcelableStatus>> results = new ArrayList<SingleResponse<ParcelableStatus>>();

    if (statusUpdate.accounts.length == 0)
        return Collections.emptyList();

    try {
        final boolean hasMedia = statusUpdate.medias != null && statusUpdate.medias.length > 0;
        final String imagePath = hasMedia ? getImagePathFromUri(this, Uri.parse(statusUpdate.medias[0].uri))
                : null;
        final File imageFile = imagePath != null ? new File(imagePath) : null;

        String uploadResultUrl = null;

        if (mUseUploader && imageFile != null && imageFile.exists()) {
            uploadResultUrl = uploadMedia(imageFile, statusUpdate.accounts, statusUpdate.text);
        }

        final String unshortenedContent = mUseUploader && uploadResultUrl != null
                ? getImageUploadStatus(new String[] { uploadResultUrl.toString() }, statusUpdate.text)
                : statusUpdate.text;

        final boolean shouldShorten = mValidator.getTweetLength(unshortenedContent) > mValidator
                .getMaxTweetLength();
        Map<Long, ShortenedStatusModel> shortenedStatuses = null;

        if (shouldShorten && mUseShortener) {
            if (mShortener.equals(SERVICE_SHORTENER_HOTOTIN)) {
                shortenedStatuses = postHototIn(statusUpdate);
                if (shortenedStatuses == null)
                    throw new ShortenException(this);
            } else if (mShortener.equals(SERVICE_SHORTENER_TWITLONGER)) {
                shortenedStatuses = postTwitlonger(statusUpdate);
                if (shortenedStatuses == null)
                    throw new ShortenException(this);
            } else {
                throw new IllegalArgumentException("BackgroundOperationService.java#updateStatus()");
            }
        }

        if (shouldShorten) {
            if (!mUseShortener)
                throw new StatusTooLongException(this);
            else if (unshortenedContent == null)
                throw new ShortenException(this);
        }
        if (!mUseUploader && statusUpdate.medias != null) {
            for (final ParcelableMediaUpdate media : statusUpdate.medias) {
                final String path = getImagePathFromUri(this, Uri.parse(media.uri));
                final File file = path != null ? new File(path) : null;
                if (file != null && file.exists()) {
                    Utils.downscaleImageIfNeeded(file, 95);
                }
            }
        }
        for (final Account account : statusUpdate.accounts) {
            String shortenedContent = "";
            ShortenedStatusModel shortenedStatusModel = null;
            final Twitter twitter = getTwitterInstance(this, account.account_id, true, true);

            if (shouldShorten && mUseShortener && shortenedStatuses != null) {
                shortenedStatusModel = shortenedStatuses.get(account.account_id);
                shortenedContent = shortenedStatusModel.getText();
            }
            final StatusUpdate status = new StatusUpdate(
                    shouldShorten && mUseShortener ? shortenedContent : unshortenedContent);
            status.setInReplyToStatusId(statusUpdate.in_reply_to_status_id);
            if (statusUpdate.location != null) {
                status.setLocation(ParcelableLocation.toGeoLocation(statusUpdate.location));
            }
            if (!mUseUploader && hasMedia) {
                final BitmapFactory.Options o = new BitmapFactory.Options();
                o.inJustDecodeBounds = true;
                final long[] mediaIds = new long[statusUpdate.medias.length];
                try {
                    for (int i = 0, j = mediaIds.length; i < j; i++) {
                        final ParcelableMediaUpdate media = statusUpdate.medias[i];
                        final String path = getImagePathFromUri(this, Uri.parse(media.uri));
                        if (path == null)
                            throw new FileNotFoundException();
                        BitmapFactory.decodeFile(path, o);
                        final File file = new File(path);
                        final ContentLengthInputStream is = new ContentLengthInputStream(file);
                        is.setReadListener(new StatusMediaUploadListener(this, mNotificationManager, builder,
                                statusUpdate));
                        final MediaUploadResponse uploadResp = twitter.uploadMedia(file.getName(), is,
                                o.outMimeType);
                        mediaIds[i] = uploadResp.getId();
                    }
                } catch (final FileNotFoundException e) {

                } catch (final TwitterException e) {
                    final SingleResponse<ParcelableStatus> response = SingleResponse.getInstance(e);
                    results.add(response);
                    continue;
                }
                status.mediaIds(mediaIds);
            }
            status.setPossiblySensitive(statusUpdate.is_possibly_sensitive);

            if (twitter == null) {
                results.add(new SingleResponse<ParcelableStatus>(null, new NullPointerException()));
                continue;
            }
            try {
                final Status twitter_result = twitter.updateStatus(status);

                //Update Twitlonger statuses
                if (shouldShorten && mUseShortener && mShortener.equals(SERVICE_SHORTENER_TWITLONGER)) {
                    TweetShortenerUtils.updateTwitlonger(shortenedStatusModel, twitter_result.getId(), twitter);
                }

                if (!notReplyToOther) {
                    final long inReplyToUserId = twitter_result.getInReplyToUserId();
                    if (inReplyToUserId <= 0) {
                        notReplyToOther = true;
                    }
                }
                final ParcelableStatus result = new ParcelableStatus(twitter_result, account.account_id, false);
                results.add(new SingleResponse<ParcelableStatus>(result, null));
            } catch (final TwitterException e) {
                final SingleResponse<ParcelableStatus> response = SingleResponse.getInstance(e);
                results.add(response);
            }
        }
    } catch (final UpdateStatusException e) {
        final SingleResponse<ParcelableStatus> response = SingleResponse.getInstance(e);
        results.add(response);
    }
    return results;
}