Example usage for twitter4j StatusUpdate media

List of usage examples for twitter4j StatusUpdate media

Introduction

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

Prototype

public StatusUpdate media(File file) 

Source Link

Usage

From source file:com.soomla.profile.social.twitter.SoomlaTwitter.java

License:Apache License

/**
 * {@inheritDoc}//from www .j  a v a 2 s. c  o m
 */
@Override
public void uploadImage(String message, String filePath,
        final SocialCallbacks.SocialActionListener socialActionListener) {
    if (!isInitialized) {
        return;
    }

    SoomlaUtils.LogDebug(TAG, "uploadImage");

    RefProvider = getProvider();
    RefSocialActionListener = socialActionListener;

    preformingAction = ACTION_UPLOAD_IMAGE;

    try {
        StatusUpdate updateImage = new StatusUpdate(message);
        updateImage.media(new File(filePath));
        twitter.updateStatus(updateImage);
    } catch (Exception e) {
        failListener(ACTION_UPLOAD_IMAGE, e.getMessage());
    }
}

From source file:it.baywaylabs.jumpersumo.twitter.TwitterListener.java

License:Open Source License

/**
 * This method is called when invoke <b>execute()</b>.<br />
 * Do not invoke manually. Use: <i>new TwitterListener().execute("");</i>
 *
 * @param params//from   w w w. ja  va 2  s  .  co m
 */
@Override
protected List<String> doInBackground(String... params) {

    Intelligence ai = new Intelligence();

    try {

        User user = twitter.verifyCredentials();
        Paging paging;
        if (idLastTwit != 0)
            paging = new Paging(idLastTwit + 1);
        else
            paging = new Paging();
        paging.count(100);
        statuses = twitter.getMentionsTimeline(paging);

        if (statuses.size() != 0 && statuses != null) {

            Log.d(TAG, "Showing @" + user.getScreenName() + "'s mentions:");
            Log.d(TAG, statuses.get(0).getText() + "-- ID: " + statuses.get(0).getId());

            if (!"".equals(statuses.get(0).getText()) && licenses.size() == 0) {

                extractCommand(ai, statuses);
                Log.d(TAG, "Non ho licenze attive!");

            } else if (!"".equals(statuses.get(0).getText()) && licenses.size() > 0
                    && f.boolContainsIgnoreCase(licenses, String.valueOf(statuses.get(0).getUser().getId()))) {

                extractCommand(ai, statuses);
                Log.i(TAG, "Seguo la lista delle licenze: " + licenses.toString());

            } else {
                publishProgress(false);
            }

            if (deviceController != null) {

                Random r = new Random();
                Interpreter interp = new Interpreter(deviceController);

                for (int i = 0; i < execute.size(); i++) {
                    Log.d(TAG, "Seguenza istruzioni rilevate: " + execute.toString());

                    if (execute.size() >= 1 && "EXECUTE".equals(execute.get(i))
                            && f.getUrls(statuses.get(0).getText()).size() != 0) {

                        String url = statuses.get(0).getURLEntities()[0].getExpandedURL();
                        // String url = f.getUrls(statuses.get(0).getText()).get(0);
                        File folder = new File(Constants.DIR_ROBOT);
                        Log.d(TAG, "URL Expanded: " + url);

                        if (downloadFileUrl(url, folder)) {
                            FileFilter ff = new FileFilter();
                            File[] list = folder.listFiles(ff);
                            Log.e(TAG, "Lista file: " + list.length);
                            if (list != null && list.length >= 1) {

                                if (list[0].getName().endsWith(".csv") || list[0].getName().endsWith(".txt")) {
                                    String commandsList = "";
                                    try {
                                        commandsList = f.getStringFromFile(list[0].getPath());
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                    Log.d(TAG, "Lista comandi: " + commandsList);
                                    interp.doListCommands(commandsList);
                                    list[0].delete();

                                    if (i == execute.size() - 1) {
                                        try {
                                            StatusUpdate reply = new StatusUpdate(
                                                    ai.actionAnswer(execute.get(i)).get(
                                                            r.nextInt(ai.actionAnswer(execute.get(i)).size()))
                                                            + "@" + statuses.get(0).getUser().getScreenName());
                                            reply.setInReplyToStatusId(statuses.get(0).getId());
                                            twitter.updateStatus(reply);
                                        } catch (TwitterException te) {
                                            Log.e(TAG, "Twitter Post Error: " + te.getMessage());
                                        }
                                    }
                                }

                            }

                        }

                    } else if (execute.size() >= 1 && "PHOTO".equals(execute.get(i))) {
                        // Download immagine e post nel tweet
                        if (interp.doCommand(execute.get(i)) == 0) {

                            String result = FTPDownloadFile(ip_host, 21, "anonymous", "", context);

                            if (i == execute.size() - 1 && !"".equals(result)) {
                                try {
                                    StatusUpdate reply = new StatusUpdate(ai.actionAnswer(execute.get(i))
                                            .get(r.nextInt(ai.actionAnswer(execute.get(i)).size())) + "@"
                                            + statuses.get(0).getUser().getScreenName());
                                    reply.setInReplyToStatusId(statuses.get(0).getId());
                                    File image = new File(Constants.DIR_ROBOT_IMG + "/" + result);
                                    Log.d(TAG, "Nome File immagine: " + image.getPath());
                                    reply.media(image);
                                    twitter.updateStatus(reply);
                                    image.delete();
                                } catch (TwitterException te) {
                                    Log.e(TAG, "Twitter Post Error: " + te.getMessage());
                                }
                            }
                        }
                    } else if (execute.size() >= 1 && !"PHOTO".equals(execute.get(i))
                            && !"EXECUTE".equals(execute.get(i))) {

                        if (interp.doCommand(execute.get(i)) == 0) {

                            if (i == execute.size() - 1) {
                                try {
                                    StatusUpdate reply = new StatusUpdate(ai.actionAnswer(execute.get(i))
                                            .get(r.nextInt(ai.actionAnswer(execute.get(i)).size())) + "@"
                                            + statuses.get(0).getUser().getScreenName());
                                    reply.setInReplyToStatusId(statuses.get(0).getId());
                                    twitter.updateStatus(reply);
                                } catch (TwitterException te) {
                                    Log.e(TAG, "Twitter Post Error: " + te.getMessage());
                                }
                            }
                        }
                    }
                }

            }
        }

        Log.d(TAG, "ready exit");

    } catch (TwitterException te) {
        te.printStackTrace();
        Log.e(TAG, "Failed to get timeline: " + te.getMessage());
    }

    return execute;
}